[英]KnockOut data-bind="visible: Need help to troubleshhot the issue
I want to hide the div if array length is >0. 如果数组长度> 0,我想隐藏div。 By putting an alert message I confirmed array length is = 0 and then div should be hidden.
通过发出警报消息,我确认数组长度为= 0,然后应隐藏div。 But when run the app div is visible.
但是在运行时,应用程序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>
You need to bind this with applybindings: 您需要使用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.