如何在淘汰赛中创建全局绑定?
我希望能够做这样的事情:
<div class="col-lg-6" data-bind="visible: IsPayingUser">
<!-- the server will not send any data for freemium,
so hide the element unless it's a paying customer -->
</div>
也就是说,我不想IsPayingUser
在每个视图模型中都创建为属性,而是只定义一次。
您可以使用window
关键字指示Knockout显式地“逃避” View-Model范围:
<div class="col-lg-6" data-bind="visible: window.UserData.IsPayingUser">
在您的JavaScript中:
window.UserData = { IsPayingUser = ko.observable(false) };
值得注意的是,“淘汰方法”是使用嵌套的视图模型,并尝试避免污染全局范围。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句