3

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

  vm.testModel= {
        testProperty:[]
    }

ページが読み込まれる前に、モデルは ko.track(vm.testModel) メソッドを使用して追跡されます。

実行時にボタンをクリックすると、次のようにこのモデルにいくつかのプロパティが追加されます。

vm.testModel.testProperty.push({ Prop1: null, Prop2: null});

UI が新しい行で更新されていることがわかります。

ここで、別のボタンをクリックすると、プロパティに値を割り当てていますが、UI はプロパティ値で更新されません。

vm.testModel.testProperty[vm.testModel.testProperty.length - 1].Prop1 = 'Test';
4

1 に答える 1

2

Arrays tracked by knockout are tracking which items are in the array, not the properties on the items in the array.

To track individual properties, you will either need to declare them as observables or pass them through ko.track

eg

vm.testModel.testProperty.push(ko.track({ Prop1: null, Prop2: null}));
于 2014-12-16T17:09:33.340 に答える