define(
['jquery', 'knockout', 'knockout.mapping', 'data/data', 'models/models'],
function ($, ko, mapping, data, models) {
var post = {},
getPost = function (param) {
$.when(data.deferredRequest('postDetail', param.id))
.done(function (result) {
mapping.fromJS(result, {}, post);
console.log(result.title === post.title()); // ---> this is true
console.log(ko.isObservable(post.title)); // ---> this is true
});
};
return {
post : post,
getPost: getPost
};
});
我要显示在HTML如下title属性:
我试过三种方式来显示title属性,但是所有这些都失败了。 我错过了什么吗?
被修改
我调整源代码如下。 我在viewmodel上添加了title属性并在getPost中更新了它,然后我成功访问了viewmodel的title属性,而不是post模型的title属性。然而,正如你所看到的data-bind =“text:title”不是帖子上的标题propery,而是viewmodel上的标题属性。这不是我想要的。我想访问post对象的title属性。
请纠正我的批准。
2012-12-09
Ray