[英]KnockOut data-bind="visible: Need help to troubleshhot the issue
如果数组长度> 0,我想隐藏div。 通过发出警报消息,我确认数组长度为= 0,然后应隐藏div。 但是在运行时,应用程序div是可见的。
<body>
<form id="form1" runat="server">
<div>
<div data-bind="visible: myValues().length > 0">
You will see this message only when 'myValues' has at least one member.
</div>
</div>
</form>
</body>
<script type="text/javascript">
var viewModel = {
myValues: ko.observableArray([]) // Initially empty, so message hidden
};
alert('The length of the array is ' + viewModel.myValues().length);
</script>
<body>
<form id="form1" runat="server">
<div>
<div data-bind="visible: myValues().length > 0">
You will see this message only when 'myValues' has at least one member.
</div>
您需要使用applybindings绑定它:
</div>
</form>
</body>
<script type="text/javascript">
var viewModel = {
myValues: ko.observableArray([]) // Initially empty, so message hidden
};
alert('The length of the array is ' + viewModel.myValues().length);
ko.applyBindings(viewModel);
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.