Ember.js QueryFixes始终返回0个结果
我在FixtureAdapter中实现了QueryFixes,以便能够进行“更复杂”的查询。我是这样做的(这是咖啡剧本): 这是我的个人资料模型+装置:Ember.js QueryFixes始终返回0个结果,ember.js,ember-data,Ember.js,Ember Data,我在FixtureAdapter中实现了QueryFixes,以便能够进行“更复杂”的查询。我是这样做的(这是咖啡剧本): 这是我的个人资料模型+装置: App.Profile = DS.Model.extend { name: DS.attr('string') businessName: DS.attr('string') picture: DS.attr('string') isBusiness: DS.attr('boolean') conversations: DS
App.Profile = DS.Model.extend {
name: DS.attr('string')
businessName: DS.attr('string')
picture: DS.attr('string')
isBusiness: DS.attr('boolean')
conversations: DS.hasMany('App.Conversation')
}
App.Profile.FIXTURES = [
{
id: 1
name: 'Jon Snow'
picture: 'https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcRDMu58ECeoIUUSMNPCEwWv4QAp4fT1fxXNK5AxK15I6GsAiBLC5Rl50zuOGQsDOedXbfE'
isBusiness: false
conversations: [101, 102]
}
{
id: 2
name: 'Jaime Lannister'
picture: 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQB_K_IfaK-da-TbwgoM1NogXSc7QPVlaxaET76D8sdMoxAd1C2WCvnsKIM8-sGFpmiPPQ'
isBusiness: true
businessName: 'Westeros Inc.'
conversations: [103]
}
]
出于测试目的,我在ApplicationRoute的init方法中对Profile进行了查询:
App.ApplicationRoute = Ember.Route.extend {
init: ->
profiles = App.Profile.find { isBusiness: false }
console.log profiles.get('length') # 0 ??
model: ->
return App.Profile.find()
}
如您所见,我在不同的位置记录fixtures.get('length')
适配器中的第一个console.log返回“2”,这是配置文件总数(OK)。
适配器中的第二个console.log返回“1”,这意味着过滤器正在工作(正常)。
但我不明白的是,为什么路由器中的第三个console.log返回“0”。好像数据没有正确返回
我不确定我是否做错了,是否是余烬数据中的错误,或者是否是预期的行为。有什么想法吗
仅供参考,以下是我的余烬配置:
Ember.VERSION : 1.0.0-rc.6
Handlebars.VERSION : 1.0.0-rc.4
jQuery.VERSION : 2.0.3
console.log输出长度0,因为fixtureAdapter正在模拟异步查询。要将查询结果大小记录到控制台,请使用
然后如下所示:
App.ApplicationRoute = Ember.Route.extend {
init: ->
profiles = App.Profile.find { isBusiness: false }
profiles.then (data) ->
console.log 'count: ', data.get('length') # 1
model: ->
return App.Profile.find()
}
JSBIN这里:谢谢!工作起来很有魅力!
App.ApplicationRoute = Ember.Route.extend {
init: ->
profiles = App.Profile.find { isBusiness: false }
profiles.then (data) ->
console.log 'count: ', data.get('length') # 1
model: ->
return App.Profile.find()
}