Store会返回多个结果

Store会返回多个结果

本文介绍了通过特定的id过滤Ext.data.Store会返回多个结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过显示ID过滤我的试听列表,但是当节目ID为1时,正在返回显示ID为1x的所有试听。以下是我的代码。

I'm trying to filter my list of auditions by show ID but when the show ID is '1' all auditions that have a show Id of '1x' are being returned. Below is my code.

试镜模型:

    Ext.regModel("Audition", {

    fields: [
        {name: "id",        type: "integer"},
        {name: "show_id",   type: "integer"},
        {name: "date",      type: "string"},
        {name: "details",   type: "string"}
    ],

    belongsTo: 'Show',

    proxy: {
        type: 'ajax',
        url : 'app/data/auditions.json',
        reader: {
            type: 'json',
            root: 'auditions',
            id  : 'id'
        }
    },

});

app.stores.auditions = new Ext.data.Store({
    autoLoad: true,
    model: 'Audition',
    sorters: 'id'
});

显示型号:

app.models.Show = Ext.regModel("app.models.Show", {

    fields: [
        {name: "id",            type: "integer"},
        {name: "title",         type: "string"},
        {name: "description",   type: "string"},
        {name: "opening_night", type: "string"},
        {name: "schedule",      type: "string"},
        {name: "producer",      type: "string"},
        {name: "director",      type: "string"},
        {name: "status",        type: "string"},
        {name: "poster",        type: "string"},
        {name: "year",          type: "string"}
    ],

    hasMany: [  {model: 'Audition', name: 'auditions'},
                {model: 'Role', name: 'roles'} ],

    proxy: {
        type: 'ajax',
        url : 'app/data/shows.json',
        reader: {
            type: 'json',
            root: 'shows',
            id  : 'id'
        }
    },

});

app.stores.shows = new Ext.data.Store({
    autoLoad: true,
    model: "app.models.Show",
    sorters: 'title',
    getGroupString : function(record) {
        return record.get('title')[0];
    }
});

以下是每个模型的json数据示例

Here's a sample of the json data for each model

试镜:

{
    "auditions": [
        {
            "id"            : "1",
            "show_id"       : "1",
            "date"          : "March 1, 2011",
            "details"       : "Details go here."
        },
        {
            "id"            : "2",
            "show_id"       : "2",
            "date"          : "March 2, 2011",
            "details"       : "Details go here."
        },
        {
            "id"            : "3",
            "show_id"       : "12",
            "date"          : "March 3, 2011",
            "details"       : "Details go here."
        }
    ]
}

显示:

{
    "shows": [
        {
            "id"            : 1,
            "title"         : "The Diary of Anne Frank",
            "status"        : "Coming Soon",
            "description"   : "Show description goes here.",
            "opening_night" : "2010-10-08",
            "schedule"      : "October 8-24, 2010",
            "producer"      : "Hello World",
            "director"      : "Hello World",
            "year"          : "2010",
            "poster"        : "thediaryofannefrank.jpg"
        },
        {
            "id"            : "2",
            "title"         : "It’s a Wonderful Life",
            "status"        : "Coming Soon",
            "description"   : "Show description goes here.",
            "opening_night" : "2010-11-26",
            "schedule"      : "November 26 - December 19, 2010",
            "producer"      : "Hello World",
            "director"      : "Hello World",
            "year"          : "2010",
            "poster"        : "itsawonderfullife.jpg"
        }
    ]
}

在每个节目的视图模板中,我通过show_id

In the view template for each show I filter the data stores for auditions by show_id

app.stores.auditions.filter('show_id', show.id);

this.showAuditionsList = new Ext.List({
  itemTpl: '{date}',
  store: app.stores.auditions
});

所以使用上面的代码,如果我在安妮·弗兰克的日记表演页面我想看节目的所有试镜 - 代码将返回试镜1和3 - 即使试镜3的show_id为12。

So using the code above, if I'm on the show page for The Diary of Anne Frank and I want to see all auditions for the show - the code will return audition 1 and 3 - even if audition 3 has a show_id of 12.

在我的测试中发现过滤器将保持所有具有1和1X的show_id的所有试镜(以1开头的任何内容)。有没有更好的方法过滤商店或更好,查询商店返回所有的试镜?

In my testing I've found that the filter will keep all auditions that have a show_id of both '1' and '1X' (anything that begins with 1). Is there a better way to filter the store or better yet, query the store to return all auditions?

谢谢!

推荐答案

还试过

app.stores.auditions.filter({
    property: 'show_id',
    value: show.id,
    exactMatch: true
});

app.stores.auditions.filterBy(function(record, id) {
    return store.id = id;
}, this);

或者如果您只想获得具体记录;

Or if you just want to get that specific record;

var record = app.stores.auditions.getAt(app.stores.auditions.findExact('store_id', store.id));

这篇关于通过特定的id过滤Ext.data.Store会返回多个结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 04:56