【发布时间】:2014-02-24 03:24:18
【问题描述】:
我试图在我的节点应用程序视图中实现一个简单的 Ember 应用程序。我知道 Ember 已设置并且我的套接字工作正常,现在唯一的问题是数据似乎没有被返回,即使它正在被检索。
这是我所拥有的:
App = Ember.Application.create({
rootElement: '#ember'
});
App.Router.map(function() {
// put your routes here
});
App.IndexRoute = Ember.Route.extend({
model: function() {
async.waterfall([
function (callback) {
socket.emit('getUserList', { data: null });
callback(null, '');
}, function (res, callback) {
var userList = new Array();
socket.on('recieveUserList', function (data) {
for(var i=0; i<data.userList.length; i++) {
userList.push(data.userList[i].name);
}
});
callback(null, userList);
}
], function (err, result) {
return result;
});
}
});
现在如果我 console.log(results) 我回来 ['John Smith', 'Jane Doe'] 但它不会在我的页面上打印出来:
<script type="text/x-handlebars">
<ul>
{{#each item in model}}
<li>{{item}}</li>
{{/each}}
</ul>
</script>
通过查看示例,它应该可以工作,对吧?
编辑 这是小提琴http://jsfiddle.net/UJ4Su/
【问题讨论】:
-
虽然很难,但请您用静态模型制作小提琴。
标签: javascript node.js sockets ember.js ejs