Filtering a Ext.data.Store by a particular id returns multiple results
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.
Audition Model:
    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'
});
Show Model:
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];
    }
});
Here's a sampl开发者_JAVA技巧e of the json data for each model
Auditions:
{
    "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:
{
    "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"
        }
    ]
}
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
});
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.
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?
Thanks!
Also have you tried
app.stores.auditions.filter({
    property: 'show_id',
    value: show.id,
    exactMatch: true
});
or
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));
I have found that to pass an object to filter it must instantiate a new filter, as per the below:
store.filter(new Ext.util.Filter({property:"foo", value:"bar", exactMatch:true});
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论