我怎样才能使它在页面加载而不是按钮单击时添加 json 数据?
http://jsfiddle.net/infatti/jWTtb/
// Here's my data model
var ViewModel = function (firstName, lastName) {
var self = this;
self.firstName = ko.observable(firstName);
self.lastName = ko.observable(lastName);
self.loadJson = function () {
$.getJSON("http://echo.jsontest.com/firstName/Stuart/lastName/Little",
function (data) {
self.firstName(data.firstName);
self.lastName(data.lastName);
});
};
};
var vm = new ViewModel();
ko.applyBindings(vm); // This makes Knockout get to work