use*_*sks 4 javascript ember.js ember-data
夹具包含联系人列表,每个联系人都有联系类型.我试图使用.findQuery()过滤联系人记录,但它抛出以下错误:
Uncaught TypeError: Object function () {.....} has no method 'findQuery'
Run Code Online (Sandbox Code Playgroud)
我在这里列出了我的代码:
Grid.Store = DS.Store.extend({
revision: 12,
adapter: 'DS.FixtureAdapter'
});
Grid.ModalModel = DS.Model.extend({
fname: DS.attr('string'),
lname: DS.attr('string'),
email: DS.attr('string'),
contactno: DS.attr('string'),
gendertype: DS.attr('boolean'),
contactype: DS.attr('number')
});
Grid.ModalModel.FIXTURES = [
{
id: 1,
fname: "sachin",
lname: "gh",
email: "gh",
contactno: "4542154",
gendertype: true,
contactype: 1
},
{
id: 2,
fname: "amit",
lname: "gh",
email: "gh",
contactno: "4542154",
gendertype: true,
contactype: 2
},
{
id: 3,
fname: "namit",
lname: "gh",
email: "gh",
contactno: "4542154",
gendertype: true,
contactype: 1
}
];
Run Code Online (Sandbox Code Playgroud)
控制器代码:
totpersonalcontact:function(){
return Grid.ModalModel.findQuery({ contactype: 2 }).get('length');
}.property('@each.isLoaded'),
totfriendcontact:function(){
return Grid.ModalModel.findQuery({ contactype: 3 }).get('length');
}.property('@each.isLoaded')
Run Code Online (Sandbox Code Playgroud)
我已将.findQuery更改为.query,但每次将长度显示为0时.
Mar*_*ior 17
只需findQuery改为query.
在此之后,控制台中将显示一条错误消息:
Assertion failed: Not implemented: You must override the DS.FixtureAdapter::queryFixtures method to support querying the fixture store.
Run Code Online (Sandbox Code Playgroud)
像消息解释一样,只需实现DS.FixtureAdapter#queryFixtures.传递给的参数queryFixtures是:记录,查询,类型.哪里:
Records 是一个普通的javascript对象数组,您将进行过滤. Query是传递给queryember数据类方法的对象.Type 是调用查询的ember数据类.返回是过滤后的数据.
例如,执行一个简单的地方,例如:
App.Person.query({ firstName: 'Tom' })
Run Code Online (Sandbox Code Playgroud)
只需重新开启DS.FixtureAdapter:
DS.FixtureAdapter.reopen({
queryFixtures: function(records, query, type) {
return records.filter(function(record) {
for(var key in query) {
if (!query.hasOwnProperty(key)) { continue; }
var value = query[key];
if (record[key] !== value) { return false; }
}
return true;
});
}
});
Run Code Online (Sandbox Code Playgroud)
这是一个现场演示.
| 归档时间: |
|
| 查看次数: |
3205 次 |
| 最近记录: |