ember.js - Can't get data from a computed property with ember-model -


i making app ember.js , ember-model

i have model named plugin defined follows:

eme.plugin = ember.model.extend   id: ember.attr()   name: ember.attr()   description: ember.attr()   downloads: ember.attr()   tags: ember.attr()  eme.plugin.url = "/api/v1/plugins" eme.plugin.adapter = ember.restadapter.create() eme.plugin.collectionkey = 'plugins' 

i want show downloaded in index.hbs ( use ember-rails)

and fetch data in indexroute 's setupcontroller hook:

eme.indexroute = em.route.extend    setupcontroller: (controller, model)->     console.log eme.plugin.findall().toarray()     controller.set 'plugins', eme.plugin.findall() 

output :

[nextobject: function, firstobject: undefined, lastobject: undefined, contains: function, geteach: function…] 

but in chrome console execute eme.plugin.findall().toarray(), got results follows:

[{   __ember1377710636537: "ember404"   __ember1377710636537_meta: meta   _dirtyattributes: array[0]   _reference: object   _super: undefined   _data: function() {}   isloaded: true   isnew: false   set _data: function(value) {}   __proto__: object }, {   ... }, {   ... }] 

in indexcontroller have computed property:

eme.indexcontroller = em.controller.extend    mostdownloads:(->     # console.log @get('plugins').slice(0, 3)     @get('plugins').slice(0, 3)   ).property('plugins') 

and iterate mostdownloads there nothing show, when output {{plugins.length}}, can't count of data

who can give hand me?

plugins looks array , need use .@each iterator so:

eme.indexcontroller = em.controller.extend({     // code }).property('plugins.@each') 

here documentation on @each http://emberjs.com/guides/object-model/computed-properties-and-aggregate-data/

regarding array length, i've never had luck using .length, length do

plugins.get('length') 

hope helps!


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -