我正在尝试使用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.
更多推荐
发布评论