gpt4 book ai didi

javascript - Durandal ko映射: mapped li not rendered in DOM

转载 作者:行者123 更新时间:2023-11-28 08:46:34 25 4
gpt4 key购买 nike

我是 Durandal 的新手。我试图使用 mimosa skelton 将新模块添加到 durandal 提供的演示应用程序中。

我按照 this 中的步骤创建了模块

当我运行应用程序时<li>与 data-bind 关联的内容不会填充到 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);
});
}
};
});

myPage.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}} 

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

最佳答案

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

我做了简单的 DEMO 重现您的问题..

请注意,没有显示任何结果,但如果您将magic []放在数据周围,使其成为单个对象的数组,您将得到Facebook 显示名称

关于javascript - Durandal ko映射: mapped li not rendered in DOM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19702140/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com