The difference between model and content attribute in Ember.js

Source: Internet
Author: User
Tags extend

Note: This article is based on Ember.js 1.4.0

In Ember.js, routing (route) sets the controller (Controller) property through the Setupcontroller method:

The code is as follows Copy Code

App.applicationroute = Ember.Route.extend ({
Model:function () {
return {' user ': ' Chen San ', ' blog ': ' http://www.111cn.net/'};
},
Setupcontroller:function (Controller, model) {
Controller.set (' model ', model); <-here, we assign the model to the Model property of the Controller
}
});

In the front-end template, you can refer directly to the properties of the object:

The code is as follows Copy Code

<script type= "Text/x-handlebars" >
User {{User}} 's blog address is {{blog}}
</script>

The page renders the result as

The user Chen San's blog address is http://www.111cn.net

But if you check the properties of Applicationcontroller with Ember.js Inspector2, the following figure:

Ember.js Check Device

We do not see a property called model, and instead, there is a content attribute that contains what we assign to the model.

What if you change the model to content in Setupcontroller?

The code is as follows Copy Code

App.applicationroute = Ember.Route.extend ({
Model:function () {
return {' user ': ' Chen San ', ' blog ': ' http://www.111cn.net/'};
},
Setupcontroller:function (Controller, model) {
Controller.set (' content ', model); <-this time, we assign the model content to the content attribute of the Controller
}
});

Practice has proved that content and model properties are equivalent.

To be more precise, model is just an alias of content set by EMBER.COMPUTED.ALIAS3 4:

The code is as follows Copy Code

Model:Ember.computed.alias (' content '),

As for why to set such an alias, you can look at a discussion on Github 5.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.