1

リスト内のチェックボックスを介してユーザーを選択できるようにしたい。

このサンプルは機能しますが、同じ方法で行うかどうかを知りたいです。

主な問題は、JavaScript の任意のオブジェクトを簡単に比較できないことです。したがって、マッピングが必要です。

これでいいの?バインディングで Id フィールドを定義できるカスタムバインディングを作成したくありません。

  function Person(id, name, age) {
    this.id = id;
    this.name = name;
    this.age = age;
  }
  function Party(id, name, persons) {
    var self = this;
    this.id = id;
    this.name = name;
    this.persons = ko.observableArray(persons);
    this.persons_checked = ko.observableArray(); //<--- for the checkboxes
    this.persons_checked.subscribe(function(newValue) {
    var mapped = [];
    mapped = $.map(newValue, function(id) { 
        return $.grep(listOfPeople, function(n) { return n.id == id; });  });
    self.persons(mapped);

});

}

完全なサンプルはこちら: http://jsbin.com/ukipek/6/edit

ありがとうございました

4

1 に答える 1