gpt4 book ai didi

knockout.js - ko.computed 不会在实例化时触发函数

转载 作者:行者123 更新时间:2023-12-04 03:21:37 24 4
gpt4 key购买 nike

嗨,有没有办法在实例化 ko.computed 时不触发函数

例子是

我有这个 ko.computed

ko.computed(function(){ alert(this.Test); } , this);

所以基本上,如果我实例化这个计算结果,这将触发那里定义的函数有没有办法在实例化时不触发它?并且仅在依赖项发生变化时才触发它?

最佳答案

您需要设置 deferEvaluation option :

deferEvaluation — Optional. If this option is true, 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/

24 4 0
文章推荐: cygwin - 在Mintty的Cygwin窗口缓冲区中搜索
文章推荐: asp.net - 如何使用 ASP.Net 将 Rtf 转换为文本?
文章推荐: asciidoctor - AsciiDoctor 中的自定义(多列)
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com