Access to the model from the template

When playing with ember, I found that sometimes the model is stored in the controller property content, sometimes the model is also available directly on the controller. However, I do not understand when this happens.

Let me explain this with the example I found when building my ember MVC.

Setting A - Start

  • I defined a user object Membercorresponding to MemberRoute, MemberViewclasses and template name Member.
  • The object Memberhad some attributes, such as id, nicknameetc.
  • NOTE : the form controller has not been defined MemberController, therefore, by agreement of ember, he himself provides the controller.

Setting B - Setting

  • Same as installing A, but now there is MemberControllerone that contains some action methods that run from the template.

Strange behavior (accordingly, what I do not quite understand)

  • in setting A, I can directly refer to attributes Memberwith {{id}}or {{nickname}}.
  • in setting B, I have to use {{content.id}}or{{content.nickname}}

As stated in the ember documentation MemberViewdoes

setupController : function(controller, member) {
    controller.set('content', member);
},

So can someone help me understand why the difference is and where is the difference? I am currently assuming that it will be

  • that the context of the template is different (maybe there is a piece of code missing in the controller configuration?)

or

  • The default controller provided by ember automatically has additional magic that may not be available for custom controllers.

, , . , . , , requireJS (, , ). Ember - v1.0pre4.

!

+5
2

, - , ? , (, )? , ember , , .

, , , MemberController Ember.Controller. , ember ( ), Ember.ObjectController. , MemberController :

App.MemberController = Ember.ObjectController.extend({
  myProperty: 'value'
});

Controller content , ember. , , content. - - :

{{content.id}} or {{content.nickname}}

, ObjectController. . EMBER GUIDES: ! .

+8

a ObjectController - , . , Ember model() function, , . , , Ember .

- , .. this = an instance of your controller or the generated one. , Ember , , , , .

, model() function , , URL-, say /foo/id that resolves against /foo/:id, Ember , Foo , model(). , .

, Ember. , , .

0

All Articles