嗨,有没有办法在实例化 ko.computed 时不触发函数
例子是
我有这个 ko.computed
ko.computed(function(){ alert(this.Test); } , this);
所以基本上,如果我实例化这个计算结果,这将触发那里定义的函数 有没有办法在实例化时不触发它?并且仅在依赖项发生变化时才触发它?
最佳答案
您需要设置 deferEvaluation
option :
deferEvaluation
— Optional. If this option istrue
, then the value of the computed observable will not be evaluated until something actually attempts to access its value or manually subscribes to it. By default, a computed observable has its value determined immediately during creation.
ko.computed(function(){ alert(this.Test); } , this, { deferEvaluation: true });
关于knockout.js - ko.computed 不会在实例化时触发函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43113909/