11

私は次のようなモデルを持っています:

TestModel = Em.Object.create({
    id:'',
    name:''
})

および次のようなオブジェクト ArrayController:

testArrayController = Em.ArrayController.create({
    content: [],
    init: function() {
        //push some object TestModel
    }
});

コンテンツ配列内のオブジェクトの id プロパティに依存するいくつかのオブジェクトを削除したい。どうやってするか?

4

2 に答える 2

4

各行の横にチェックボックスがあるテーブルがある状況がありました。

ボタンがクリックされたときに選択されていた各行を削除したかったのです。

各チェックボックスは、項目コントローラーの isSelected プロパティにバインドされていました。

removeObjectsおよび filterProperty 関数を使用してアイテムを削除しました。

this.removeObjects(this.filterProperty('isSelected'));

例を含むjsbinを次に示します。

これらは重要なビットです:

App.IndexController = Ember.ArrayController.extend({
  itemController: 'IndexItem',
  actions: {
    removeSelected: function() {
      this.removeObjects(this.filterProperty('isSelected'));
    }
  }
});

App.IndexItemController = Ember.ObjectController.extend({
  isSelected: true
});
于 2013-10-17T11:41:32.367 に答える