无论如何使用Chrome调试器检查淘汰观察者?(Is there anyway to inspect knockout observables using Chrome debugger?)

编程入门 行业动态 更新时间:2024-10-28 14:27:27
无论如何使用Chrome调试器检查淘汰观察者?(Is there anyway to inspect knockout observables using Chrome debugger?)

我正在尝试使用Chrome调试器检查observable。 我正在使用knockout插件,但它没有显示我感兴趣的observable的信息。我一直使用的解决方法是将observable设置为全局窗口对象并在控制台中检查它。 由于几个原因,这是耗时的。

I am trying to inspect observables using the Chrome debugger. I am using the knockout plugin, but it isn't showing information on the observables I'm interested in. The workaround I've been using is to set the observable to the global window object and inspect it in the console. This is time consuming for several reasons.

最满意答案

如果您正在使用非缩小的挖空库,则可以检查在每个未计算的可观察对象上公开的_latestValue变量。 在computed s,IIRC的情况下,您可以在computed上的公开state变量中找到公开的_latestValue变量。

总而言之, 如果您参考了knockout的调试(又称非缩小)构建 ,您可以通过这些变量检查可观察量。

var observable = ko.observable(); var computed = ko.computed(...); ... observable._latestValue; computed._state.latestValue;

编辑:我已修复computed的情况,但请注意,如果您使用的是最新的淘汰赛(版本> = 3.4.1),您也可以直接使用computed._latestValue ,因为它暴露出来就像一个observable 。

If you're using the non-minified knockout library, you can inspect the _latestValue variable which is exposed on each non-computed observable. In the case of computeds, IIRC you can find an exposed _latestValue variable in the exposed state variable on the computed.

So to summarize, you can inspect the observables via these variables if you're referencing the debug (aka. non-minified) build of knockout.

var observable = ko.observable(); var computed = ko.computed(...); ... observable._latestValue; computed._state.latestValue;

EDIT: I've fixed the case for computed, but note, that if you're using the latest knockout (version >= 3.4.1), you can directly use computed._latestValue too, as it got exposed just as for an observable.

更多推荐

本文发布于:2023-07-24 00:34:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1239338.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:观察者   如何使用   调试器   Chrome   debugger

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!