Фильтрация Ext.data.Store по определенному идентификатору возвращает несколько результатов - PullRequest
1 голос
/ 04 марта 2011

Я пытаюсь отфильтровать свой список прослушиваний по идентификатору шоу, но когда идентификатор шоу равен '1', возвращаются все прослушивания с идентификатором показа '1x'.Ниже приведен мой код.

Модель прослушивания:

    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 для каждой модели

Прослушивания:

{
    "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

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.

В моем тестировании я обнаружил, что фильтр будет сохранять все прослушивания, которые имеют show_id как '1' и '1X' (все, что начинается с 1).Есть ли лучший способ отфильтровать магазин или еще лучше, запросить магазин, чтобы вернуть все прослушивания?

Спасибо!

Ответы [ 2 ]

6 голосов
/ 04 марта 2011

Также вы пробовали

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

или

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

Или если вы просто хотите получить эту конкретную запись;

var record = app.stores.auditions.getAt(app.stores.auditions.findExact('store_id', store.id));
0 голосов
/ 06 марта 2013

Я обнаружил, что для передачи объекта на фильтрацию необходимо создать новый фильтр, как показано ниже:

store.filter(new Ext.util.Filter({property:"foo", value:"bar", exactMatch:true});
...