【问题标题】:Unable to update observable value in subscribe method无法更新订阅方法中的可观察值
【发布时间】:2014-01-31 23:40:15
【问题描述】:

我有一个订阅功能,它会在下拉列表值更改时触发。我想更新这个订阅函数中的另一个可观察值。问题是当控件离开此订阅函数时,可观察值变为空或为空。

self.selectedSubAccount.subscribe(function (newValue) {
 //alert("The Selected Account Code:" + newValue);
 var likeCode = newValue.substring(0, 2);
 var accType = "Control";
 self.ACCOUNT_CODE = GenrateAccountCode(self.SUBACCOUNTS(), likeCode, accType);
});

【问题讨论】:

  • 您的代码中可以观察到哪个属性?是self.ACCOUNT_CODE吗?

标签: knockout.js subscribe


【解决方案1】:

假设 self.ACCOUNT_CODE 是你的 observable,你会像这样更新它:

self.ACCOUNT_CODE(GenrateAccountCode(self.SUBACCOUNTS(), likeCode, accType));

【讨论】:

    猜你喜欢
    • 2021-06-14
    • 2018-02-03
    • 1970-01-01
    • 2019-11-15
    • 2016-06-10
    • 1970-01-01
    • 1970-01-01
    • 2018-03-24
    • 1970-01-01
    相关资源
    最近更新 更多