1

いくつかのソーター セットを事前に定義したい店舗があります。最初に、バンド ランク、lastName による並べ替え順序を定義しました。

ここに画像の説明を入力

        {
        property: 'rank',
        direction: 'ASC'
        },
        {
        property: 'lastName',
        direction: 'ASC'
        }

2 番目の例では、ソーターを年、バンド、姓で表示します。

    {
    property: 'year',
    direction: 'ASC'
    },
    {
    property: 'band',
    direction: 'ASC'
    },
    {
    property: 'lastName',
    direction: 'ASC'
    }

ストアで最初のソーターを 2 番目のソーターと交換し、必要に応じて元に戻すにはどうすればよいですか?

残りのコードは次のとおりです。

BandMemberStore.js:

Ext.define('Sencha.store.BandMemberStore', {
    extend: 'Ext.data.Store',

    requires: [],

    config: {
        model: 'Sencha.model.BandMember',
        autoLoad: true,
        defaultRootProperty: 'items',

        proxy: {
            type: 'ajax',
            url: 'bands.json',
            reader: {
                type: 'json',
                rootProperty: 'items'
            }
        },
    sorters : [
        {
        property: 'rank',
        direction: 'ASC'
        },
        {
        property: 'lastName',
        direction: 'ASC'
        }
    ]
    },

    load: function () {
        this.callParent(arguments);
    }
});

モデル:

Ext.define('Sencha.model.BandMember'    , {
    extend: 'Ext.data.Model',

    config: {
        fields: [
            {name: 'rank', type: 'int'},
            {name: 'band', type: 'string'},
            {name: 'year', type: 'int'},
            {name: 'firstName', type: 'string'},
            {name: 'lastName', type: 'string'},
            {
                name: 'fullName',
                type: 'string',
                convert: function (value, record) {

                    firstName = record.data.firstName;
                    lastName = record.data.lastName;
                    fullName = firstName + " " + lastName;
                    return fullName;
                }
            }
        ]
    },
    load: function () {
        this.callParent(arguments);
    }
});

app.js:

Ext.Loader.setConfig({enabled: true});

Ext.application({
    name: "Sencha",

    models: ['BandMember'],
    stores: ['BandMemberStore'],
    views: [],
    controllers: [],

    launch: function () {
        console.log("Launching");

        var aList = Ext.create("Ext.List", {
            fullscreen: true,
            store: 'BandMemberStore',
            itemTpl: "{rank} / {year} / {band} / {lastName}, {firstName} - {fullName}"
        });
        Ext.Viewport.add(aList);
    }
});

バンド.json:

{"items": [
    { "rank": 3, "band": "Eagles" , "year": "1971", "firstName": "Glenn", "lastName": "Fry" },
    { "rank": 3, "band": "Eagles" , "year": "1971", "firstName": "Don", "lastName": "Henley" },
    { "rank": 3, "band": "Eagles" , "year": "1971", "firstName": "Joe", "lastName": "Walsh" },
    { "rank": 3, "band": "Eagles" , "year": "1971", "firstName": "Timothy", "lastName": "Schmit" },

    { "rank": 2, "band": "Beatles" , "year": "1960", "firstName": "John", "lastName": "Lennon" },
    { "rank": 2, "band": "Beatles" , "year": "1960", "firstName": "Paul", "lastName": "McCartney" },
    { "rank": 2, "band": "Beatles" , "year": "1960", "firstName": "George", "lastName": "Harrison" },
    { "rank": 2, "band": "Beatles" , "year": "1960", "firstName": "Ringo", "lastName": "Starr" },
    { "rank": 1, "band": "Rolling Stones" , "year": "1962", "firstName": "Mick", "lastName": "Jaggar" },
    { "rank": 1, "band": "Rolling Stones" , "year": "1962", "firstName": "Keith", "lastName": "Richards" },
    { "rank": 1, "band": "Rolling Stones" , "year": "1962", "firstName": "Charlie", "lastName": "Watts" },
    { "rank": 1, "band": "Rolling Stones" , "year": "1962", "firstName": "Ron", "lastName": "Wood" },
]}
4

1 に答える 1

7
 var sorters1 = [  {
            property: 'rank',
            direction: 'ASC'
            },
            {
            property: 'lastName',
            direction: 'ASC'
            }],
       sorters2 = [ {
        property: 'year',
        direction: 'ASC'
        },
        {
        property: 'band',
        direction: 'ASC'
        },
        {
        property: 'lastName',
        direction: 'ASC'
        }],
       store = Ext.getStore('YourStoreIdHere');

    //use first sorters
    store.sort(sorters1);
    //use second sorters
    store.sort(sorters2);

    //or you can just change sorters by
    store.setSorters(sorters2);
于 2013-08-13T18:18:00.957 に答える