1

我是杜兰达尔的新手。我试图在 durandal 使用 mimosa skelton 提供的演示应用程序中添加一个新模块。

我按照此步骤创建了模块

当我运行<li>与数据绑定关联的应用程序时,DOM 中没有填充。即,页面中不显示任何数据。

但是当我使用 console.log 在 myPage.js 中打印数据时,它会给出所需的输出。

我的模块 backend.js

define(function(require){
  return {
    getCustomers:function(){
      //do some ajax and return a promise
        return $.ajax({
          url: 'http://graph.facebook.com/facebook?callback=?',
          dataType: 'json',
        }).promise();
    }
  };
});

我的 myPage.js

define(function (require) {
    var backend = require('backend');
    var ko = require('knockout');

    return {
        customer:ko.observableArray([]),
        activate:function(){
          var that = this;
          return backend.getCustomers().then(function(result){
            that.customer(result);
          });
        }
      };
});

我的页面.html

<div>
  <h2>FB Page Detail</h2>
  <ul data-bind="foreach: customer">
    <li data-bind="text: name"></li>
  </ul>
</div>

获得的结果

{"about":"Facebook's mission is to give people the power to share and make the world more open and connected.","category":"Product/service","company_overview":"Newsroom: http://newsroom.fb.com\nInvestor Relations: http://investor.fb.com/","founded":"February 4, 2004","is_published":true,"talking_about_count":207120,"username":"facebook","website":"http://www.facebook.com/facebook","were_here_count":0,"id":"20531316728","name":"Facebook","link":"http://www.facebook.com/facebook","likes":96174118,"cover":{"cover_id":"10151496277356729","source":"http://sphotos-a.ak.fbcdn.net/hphotos-ak-ash2/s720x720/247388_10151496277356729_2043388331_n.jpg","offset_y":0,"offset_x":0}} 

我做错什么了?如何解决这个问题?

4

2 回答 2

1

我认为你的问题是关于你如何使用knockoutJS而不是durandal ..你正在将object(单个对象)传递给你的observableArray..虽然你应该传递对象数组或一个对象数组..

我做了简单的演示来重现你的问题..

请注意,没有显示任何结果,但是如果您将数据放在单个 []对象的数组中,则会Facebook显示名称

于 2013-10-31T10:59:34.337 回答
-1

不确定您如何在此处应用绑定,您可能需要使用,因为您的模型在视图模型中设置为客户属性。
data-bind="html:customer.name"

于 2013-10-31T09:03:28.373 回答