在下面的代码中,如何将数据从my.Author
函数返回到页面,我知道我在这里遗漏了一些东西。这是一个精简的vm。如果可能的话,我想保留这个基本结构。
在控制台中我可以看到'my.Author'正在接收一个值,但没有任何内容打印到页面。
my.Author = function () {
var self = this;
self.authorid = ko.observable();
self.authorname = ko.observable();
self.authorprofile = ko.observable();
self.gotoUrl = ko.computed(function () {
return goToAuthor + self.authorid();
}, self);
self.gotoAuthorEditUrl = ko.computed(function () {
return goToAuthorEdit + self.authorid();
}, self);
};
my.vm = (function () {
loadAuthorCallback = function (data) {
my.Author.authorname = data.AuthorName;
my.Author.authorid = data.AuthorId;
my.Author.authorprofile = data.AuthorProfile;
},
loadAuthor = function () {
my.DataService.getAuthor(my.vm.loadAuthorCallback);
};
return {
Author: my.Author(),
loadAuthorCallback: loadAuthorCallback,
loadAuthor: loadAuthor
};
})();
my.vm.loadAuthor();
ko.applyBindings(my.vm);
谢谢&问候 熔体