我一直在尝试将 Ember 与 JSON 服务器一起使用,但没有使用 ember-data。我的测试应用程序从一个小的 JSON 结构(从一个小的 Go 服务器生成)呈现一个图像目录。
谁能向我解释为什么,如果我在下面的代码中取消注释 App.FileController,相应的文件视图无法呈现?
window.App = Ember.Application.create();
App.Router.map(function() {
this.resource('files',function(){
this.resource('file',{path:':file_id'});
});
});
App.FilesRoute = Ember.Route.extend({
model: function() {
return App.File.findAll();
}
});
App.FileRoute = Ember.Route.extend({
setupController: function(controller, args) {
controller.set('model', App.File.find(args.id));
},
model: function(args) {
return App.File.find(args.file_id);
}
});
App.File = Ember.Object.extend({
urlPath: function(){
return "/pics/" + this.get('id');
}.property('id'),
});
如果我取消注释,事情就会中断:
// App.FileController = Ember.Controller.extend({
// });
(即,文件子视图根本不再呈现。)
App.File.reopenClass({
find: function(id){
file = App.File.create({'id':id});
return file;
},
findAll: function() {
return $.getJSON("http://localhost:8080/api/").then(
function(response) {
var files = [];
response.Files.forEach(function (filename) {
files.push(App.File.create({'id':filename}));
});
return files;
}
);
},
});
另外,我在这里做错了什么基本的事情吗?