2

サーバーからのデータを入力しているモデルがあります。問題は、そのデータが最初に入力されたときに、サブスクリプションが起動していることです。ユーザーがUIを操作したときにのみサブスクリプションを起動したい。

function ViewModel() {
    var self = this;

    //Populate the object.
    self.request = new Request(data);
    //Subscribe to one of the "properties" so that I can do stuff when the value changes.
    self.request.selectedId.subscribe(function(newValue) {
        //This is firing before the user interacts with the UI.
    });
}
4

1 に答える 1

2

通常、そのために手動のサブスクリプションは必要ありませんが、何かを一度だけ行う必要があるためにそれらを保持したい場合は、一度トリガーするフラグをいつでも使用できます。

self.initialLoad = true;
self.request.selectedId.subscribe(function(newValue) {
    if(self.initialLoad) self.initialLoad = false
    else {
    //This is firing before the user interacts with the UI.
    }
});
于 2013-01-08T22:54:44.367 に答える