I want to iterate an Emebrjs collection – each time a user clicks next the following item is selected and its property changes:
How do I iterate the list view item from outside?
see –
http://jsfiddle.net/gavriguy/NHxJ4/
var App = Em.Application.create({
ready: function() {
App.someItemsView.appendTo('body');
this._super();
}
});
App.tempController = Em.ArrayController.create({
self: this,
foo: {title:'tt'},
content: [
{
title: 'A',
unread: true},
{
title: 'B',
unread: false},
{
title: 'C',
unread: false}
],
init: function() {},
highlightNext: function() {
var currentItem = this.content.filterProperty('unread', false)[0];
//How to change the current item's unread to true???
}
});
App.someItemsView = Ember.CollectionView.create({
contentBinding: 'App.tempController.content',
itemViewClass: Ember.View.extend({
template: Ember.Handlebars.compile('<div>{{content.title}} unread: {{content.unread}}</div>'),
click: function(event) {
this.setPath('content.unread', false);
}
}),
});
Since your items in the
App.tempController.contentarray are notEmber.Object‘s, you can’t usecontent.set('unread', false). If you want to change a property of a non Ember object, you can use theEmber.setPathfunction, see http://jsfiddle.net/pangratz666/7RLDr/: