【发布时间】:2014-09-18 09:10:58
【问题描述】:
我有一个带有 Fixtures 数据集的模型,因此这里不涉及后端。对于模型,我有 22 条数据记录。当我第一次在我的 IndexRoute 中查询它时,会返回所有 22 条数据记录。这里没问题。
当我离开路由,稍后再回来时,我的 IndexRoute 的模型钩子再次被调用,但这一次相同的查询没有返回数据。
我的模型钩子看起来像:
model: function () {
var placeId = 0;
console.log('Index Route: Model Hook');
console.log('Getting hints for place ' + placeId);
this.get('store').find('hint', { place: placeId })
.then(
function (hints) {
console.log('Found hints', hints.get('content'));
}
);
return this.get('store').find('hint', { place: placeId });
}
如您所见,出于演示目的,我总是查询地点 id 为零的提示。如前所述,它第一次返回数据(我可以在 Chrome Ember Inspector 中看到数据),但第二次进入此路由时不会返回数据(我知道它就在那里)。
编辑: 我的提示模型看起来基本上像
App.Hint = DS.Model.extend({
title: DS.attr('string'),
// some basic boring attributes
place: DS.belongsTo('place', { async: true }) // Association with my Place Model
});
App.Place = DS.Model.extend({
title: DS.attr('string'),
// some more attributes
hints: DS.hasMany('hint', { async: true })
});
所以查询{place: placeId} 只是获取所有与特定地点有关联的提示。问题不在于查询不起作用 - 它在第一次触发索引路由时起作用(并且它像我期望的那样起作用)。问题是索引路由的所有后续调用以及所有其他尝试访问提示的位置都不再起作用并且总是返回一个空集。
【问题讨论】:
标签: ember.js ember-data ember-router