Yo-6ren">
gpt4 book ai didi

arrays - KnockOut 数据绑定(bind) =“可见 : Need help to troubleshhot the issue

转载 作者:行者123 更新时间:2023-12-03 11:55:56 24 4
gpt4 key购买 nike

如果数组长度>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 绑定(bind)它:

    </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>

关于arrays - KnockOut 数据绑定(bind) =“可见 : Need help to troubleshhot the issue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25616253/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com