所以有很多Ember.js在线的例子,但是看一下这个例子:
http://matthewlehner.net/get-started-with-ember-js-in-5-minutes/
最终得到以下路线对象:
Test1.ApplicationRoute = Ember.Route.extend({
// admittedly, this should be in IndexRoute and not in the
// top level ApplicationRoute; we're in transition... :-)
model: function () {
return ['red', 'yellow', 'blue'];
}
});
作为第一步,我想用JSON请求替换该模型,因此在线查看一些示例我尝试了这个:
return $.getJSON('/colors.json');
其中colors.json是一个文件:
['red', 'yellow', 'blue']
我已经尝试了一些变体,但它总是在我的浏览器中给我这个错误:“加载路径时出错:未定义”
有人可以告诉我如何使其正常工作吗?
有关“之前”状态的示例,请参阅http://jsbin.com/lususavo/4/。如何使用getJSON?
答案 0 :(得分:0)
我不确定为什么要将所有内容包装在函数中,在页面准备好之前Ember不会启动。 (说实话,我可能只是不理解。)
无论哪种方式都是getJSON的例子
App.IndexRoute = Ember.Route.extend({
model: function() {
return $.getJSON('/colors.json');
}
});