ember.js - How do I access a model in a controller? -


this pretty basic, reason can't working.

i've created companies resource:

app.router.map(function() {     this.resource('companies'); }); 

and specified model

app.company = ds.model.extend({     name: ds.attr('string'), });  app.companiesroute = ember.route.extend({     model: function() {         return app.company.find();     } }); 

i have fixtures test data.

now, shouldn't have access companies data controller? this

app.companiescontroller = ember.arraycontroller.extend({     length: function () {         return this.get('length');     }.property(), }); 

i'm getting 0, , i've tried in function makes me think somehow controller isn't getting loaded data - though able loop through models in template, this:

  <script type="text/x-handlebars" data-template-name="companies">     <div class="row">       <div class="span12">         <h3>companies</h3>         {{#each controller}}           <li>{{ name }}</li>         {{/each}}         </ul>       </div>     </div>   </script> 

some parts of docs show setupcontroller instead of model: function() {}, i'm not clear differences. i've tried both, no success.

any ideas?

your should declare path of property (or properties), computed property depends on. in case, content.length:

app.companiescontroller = ember.arraycontroller.extend({     length: function () {         return this.get('content.length');     }.property('content.length'), }); 

or use binding:

app.companiescontroller = ember.arraycontroller.extend({     lengthbinding: 'content.length' }); 

but computed properties require less work bindings (internally), , in general faster.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -