<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script src="js/jquery-1.11.1.min.js"></script>
    <script src="js/knockout-3.3.0.js"></script>
    <script>
        var viewModel = {
            shouldShowMessage: ko.observable(true) 
        };

        var myViewModel = {
            myValues: ko.observableArray([])
        };

        $(function () {
            viewModel.shouldShowMessage(true);
            myViewModel.myValues.push("some value");
            ko.applyBindings(viewModel, $("#no1")[0]);
            ko.applyBindings(myViewModel, $("#no2")[0]);
        })
    </script>
</head>
<body>
    <div id="no1" data-bind="visible: shouldShowMessage">
        You will see this message only when "shouldShowMessage" holds a true value.
    </div>
    <div id="no2" data-bind="visible: myValues().length > 0">
        You will see this message only when 'myValues' has at least one member.
    </div>
</body>

 

相关文章:

  • 2022-12-23
  • 2022-02-20
  • 2021-09-13
  • 2021-06-25
  • 2021-09-09
  • 2021-11-22
  • 2021-09-03
  • 2022-03-04
猜你喜欢
  • 2021-10-29
  • 2022-01-03
  • 2021-11-29
  • 2021-08-05
  • 2021-05-20
  • 2021-08-14
相关资源
相似解决方案