0
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>

问题:如何在我的视图中获取用户名。我可以获得messagemessageDateTime而不是用户数据。我认为ko.mapping.fromJS应该将我的数据映射到 observableArray 或者我错过了什么?

4

0 回答 0