发布于 2017-01-11 21:46:27 | 159 次阅读 | 评论: 0 | 来源: 网友投递
Knockout.js JavaScript的UI库
Knockout 是个JavaScript library,帮助创建丰富的显示和编辑器UI,通过干净的底层数据模型。你可以在任何时候动态更新UI的选择部分。
var AppViewModel = {
shouldShowMessage: ko.observable(true) ///初始化的时候div是visible的
};
AppViewModel.shouldShowMessage = ko.observable(false); ///现在hidden勒
ko.applyBindings( AppViewModel);
<div data-bind="visible:shouldShowMessage">
You will see this message only when "shouldShowMessage" holds a true value.
</div>
<script type="text/javascript">
var AppViewModel = {
shouldShowMessage: ko.observable(true), ///初始化的时候div是visible的
myValues: ko.observableArray([])
};
AppViewModel.shouldShowMessage = ko.observable(false); ///现在hidden勒
AppViewModel.myValues.push("some value"); ///向myValues数组中 添加一个项
ko.applyBindings( AppViewModel);
</script>
<div data-bind="visible: myValues().length > 0">
You will see this message only when 'myValues' has at least one member.
</div>