【发布时间】:2017-06-02 21:59:03
【问题描述】:
我有一个 ASP.NET 应用程序,我正在使用 Knockout JS 在我的应用程序中执行一些最小的任务。但是我有一些 EditorTemplates 正在计算要显示的值。我想从其他一些 EditorTemplates 访问这些值。我想我可能会在 Knockout 中使用本机 pub/sub 功能,这意味着我会在一个 EditorTemplate 中编写通知代码,如下所示:
new ko.subscribable().notifySubscribers(this.calculatedValue, "customTopic");
然后在我的其他 EditorTemplate 中更改时接收此值
new ko.subscribable().subscribe(function (newValue) {
alert(newValue);
}, this, "customTopic");
当然,这段代码不起作用,因为我每次都在创建一个new ko.subscribable()。
如何创建一个在我的所有视图中都可用的ko.subscribable?
【问题讨论】:
标签: asp.net knockout.js