[英]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.