【发布时间】:2013-08-21 22:54:12
【问题描述】:
因此,我正在尝试使用来自 API 端点 /categories 的数据和 Ember 数据在我的 Ember 应用程序中动态构建路由。为了做到这一点,我在我的模型中添加了一个didLoad 方法,该方法由控制器调用并设置为该控制器的属性。我将路由映射到我的路由器,一切正常。当我尝试使用 findQuery 检索到的服务器中的数据设置内容属性时,真正的麻烦就开始了。
这是错误:
TypeError {} "Object /categories/548/feeds has no method 'eachRelationship'"
这是代码:
window.categoryRoutes = [];
App.Categories = DS.Model.extend({
CATEGORYAFFINITY: DS.attr('boolean'),
CATEGORYID: DS.attr('number'),
CATEGORYNAME: DS.attr('string'),
CATEGORYLINK: function () {
var safeUrl = urlsafe(this.get('CATEGORYNAME'));
categoryRoutes.push(safeUrl);
return safeUrl;
}.property('CATEGORYNAME'),
didLoad: function () {
var categoryLink = this.get('CATEGORYLINK');
var categoryId = this.get('CATEGORYID');
App.Router.map(function () {
this.resource(categoryLink, function () {
// some routes
});
});
App[Ember.String.classify(categoryLink) + 'Route'] = Ember.Route.extend({
setupController: function(controller, model) {
// source of error
this.controllerFor(categoryLink).set(
'content',
this.store.findQuery('/categories/' + categoryId + '/feeds', {
appid: 'abc123def456',
lat: 39.75,
long: -105
})
);
}
});
}
});
感谢任何“暂停”!
另外,如果我这样做完全错误,并且有一种更像 Ember 的方式来做到这一点,我想知道。
【问题讨论】:
-
另外,我忘了提一下,我在 CommonJS -shims 包中使用了来自 Bower 的 Ember 1.0.0-rc.7 和 Ember Data r13.1。
标签: javascript model-view-controller ember.js ember-data