I have a model like:
TestModel = Em.Object.create({
id:'',
name:''
})
and a object ArrayController like:
testArrayController = Em.ArrayController.create({
content: [],
init: function() {
//push some object TestModel
}
});
I want to remove some objects depend on id property of a object in content array. How to do that?
I would use a combination of findProperty
and removeObject
, see http://jsfiddle.net/pangratz666/rXN4E/:
App.testArrayController = Em.ArrayController.create({
content: [],
removeItem: function(propName, value){
var obj = this.findProperty(propName, value);
this.removeObject(obj);
}
});
App.testArrayController.removeItem('id', 42);
I had a situation where I had a table with a checkbox next to each row.
I wanted to remove each row that had been selected when a button was clicked.
Each checkbox was bound to an isSelected property on the item controller.
I used the removeObjects and filterProperty functions to remove the items:
this.removeObjects(this.filterProperty('isSelected'));
Here is a jsbin with an example.
These are the important bits:
App.IndexController = Ember.ArrayController.extend({
itemController: 'IndexItem',
actions: {
removeSelected: function() {
this.removeObjects(this.filterProperty('isSelected'));
}
}
});
App.IndexItemController = Ember.ObjectController.extend({
isSelected: true
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With