javascript - How to get a random value from a Fixture Data in Ember -
i'm playing sample ember app shows data stored in fixture, , tries show random data fixture.
complete demo here: http://jsbin.com/ifatot/2/edit
everything works fine, however, i'm not able random index out of ember data. i'm trying find length , grab random index believe length coming 0, though have data in there.
the function looks this:
app.thoughtscontroller = ember.arraycontroller.extend({ randommessage: function() { var thoughts = this.get('model'); var len = thoughts.get('length'); var randomthought = (math.floor(math.random()*len)); return thoughts.objectat(randomthought); }.property('model') });
you should add length
property dependent on randommessage
computed property. allow content have finished resolving , have length
.
randommessage: function() { var len = this.get('length'); var randomthought = (math.floor(math.random()*len)); return this.objectat(randomthought); }.property('model', 'length')
here's updated jsbin.
Comments
Post a Comment