1

ユーザーがアイテムをクリックするforeach(over Foos)テーブルがあり、このメソッドは次のように呼び出されます。

 AddFoo = function (addingItem) {
        var addingItem = jQuery.extend(true, {}, existingObservableBoundToJqueryDialogue);
        this.Foos.push(addingItem);  //EditingItem is bound to the add dialogue, and I want a new observable with the same properties not bound to the dialogue

    };

私が抱えている問題は、テーブル内のこのオブザーバブル(新しいaddingItem)を編集すると、この方法で追加されたすべてのアイテム(各addingItem)が変更されることです。

4

1 に答える 1

1

非常に迅速な解決策は、ノックアウトマッピングプラグインを使用してプレーンなバニラjsonオブジェクトを作成し、そこから新しいノックアウトモデルを作成することです。

var addingItem = ko.mapping.fromJS(ko.mapping.toJS(existingObservableBoundToJqueryDialogue));

これにより、observableがアンラップされ、その値から別の値が作成されます:)

jsfiddleの作業サンプル

于 2013-03-07T15:18:16.490 に答える