var data=[
{
id: 25,
message: "4",
messageDateTime: "2013-07-14T20:01:17.46",
userId: 1,
user: {
id: 1,
userName: "User A",
password: "AAA",
email: "email",
fullName: "Full Name A"
}
},
{
id: 24,
message: "3",
messageDateTime: "2013-07-14T20:01:16.42",
userId: 1,
user: {
id: 1,
userName: "User A",
password: "AAA",
email: "email",
fullName: "Full Name A"
}
}]
查看模型
var viewModel = ko.mapping.fromJS(data);
查看:
<h2 data-bind="text: user.userName"></h2>
<p data-bind="text: message"></p>
<p data-bind="text: messageDateTime"></p>
问题:如何在我的视图中获取 userName 。我可以获取消息和 messageDateTime 而不是用户数据。我认为 ko.mapping.fromJS 应该将我的数据映射到observableArray或者我错过了什么?