发布于 2017-01-14 12:36:28 | 141 次阅读 | 评论: 0 | 来源: 网友投递
Knockout.js JavaScript的UI库
Knockout 是个JavaScript library,帮助创建丰富的显示和编辑器UI,通过干净的底层数据模型。你可以在任何时候动态更新UI的选择部分。
Today's message is: <span data-bind="text: myMessage"></span>
<script type="text/javascript" src="~/Scripts/knockout-2.3.0.debug.js"></script>
<script type="text/javascript">
var viewModel = {
myMessage: ko.observable()
};
viewModel.myMessage("Hello, world!");
ko.applyBindings(viewModel);
</script>
price: ko.observable(24.95)
viewModel.priceRating = ko.dependentObservable(
function () {
return this.price() > 50 ? "expensive" : "affordable";
}, viewModel);
The item is <span data-bind="text: priceRating"></span> today.
viewModel.myMessage("<i>Hello, world!</i>");