码迷,mamicode.com
首页 > 其他好文 > 详细

Knockout

时间:2014-05-08 21:03:59      阅读:282      评论:0      收藏:0      [点我收藏+]

标签:ext   c   string   html   set   cti   

<button id="load">Load</button>
<ul data-bind="template: { foreach: vendors }">
<li><span data-bind="text: Id"></span></li>
</ul>

 

 

 

var data = [];
var viewModel = {
vendors: ko.observableArray(data)
};
ko.applyBindings(viewModel);

$(function () {
// on this click event, we popular the observable array
$(‘#load‘).click(function () {
// WORKS. Html is updated appropriately.
viewModel.vendors([{ "Id": "01" },{ "Id": "02" },{ "Id": "03" }]);

$.ajax({
url: ‘/echo/json/‘,
type: "POST",
/*contentType: "application/json; charset=utf-8",*/
data:{
json: JSON.stringify( {
result:[{ "Id": "02" },{ "Id": "03" },{ "Id": "04" }]
}),
delay: 3
},
dataType: ‘json‘,
success: function (data) {
console.log(data);
viewModel.vendors(data.result);
}
});
});
});

Knockout,布布扣,bubuko.com

Knockout

标签:ext   c   string   html   set   cti   

原文地址:http://www.cnblogs.com/zwei1121/p/3709392.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!