0

ストアを定義していて、作成時にモデルを動的に割り当てたいと考えています。したがって、自分で作成しDropDownStore、モデル構成を渡さない場合は、デフォルトのモデル(DropDownModel)に依存する必要があります。

これが私のDropDownModel+DropDownStoreです:

Ext.define('DropDownModel', {
    extend: 'Ext.data.Model',
    fields: [
        { name: 'Id', type: 'int' },
        { name: 'Name', type: 'string' }
    ]
});
Ext.define('DropDownStore', {
    extend: Ext.data.Store,
    proxy: {
        type: 'ajax',
        actionMethods: { read: 'POST' },
        reader: {
            type: 'json',
            root: 'data'
        }
    },
    constructor: function(config) {
        var me = this;

        if (config.listUrl) {
            me.proxy.url = config.listUrl;
        }

        me.model = (config.model) ? config.model : 'DropDownModel'; //This line creates some weird behaviour

        me.callParent();

        //If the URL is present, load() the store.
        if (me.proxy.url) {
            me.load();
        }
    }
});

これは、DropDownStore動的モデルを使用したの作成です。

Ext.define('RelationModel', {
    extend: 'Ext.data.Model',
    fields: [
        { name: 'Id', type: 'int' },
        { name: 'RelationName', type: 'string' },
        { name: 'RelationOppositeName', type: 'string' }
    ]
});

...//a random combobox
store: Ext.create('DropDownStore', {
    listUrl: 'someprivateurl',
    model: 'RelationModel'
})
...

constructorメソッドの行を次のように編集する
me.model = (config.model) ? config.model : undefined
と、動的モデルでは期待どおりに機能しますが、デフォルトモデルでは機能しなくなります。

そのままにしておくと
me.model = (config.model) ? config.model : 'DropDownModel';
、動的モデルではなく、デフォルトモデルで機能します。

作成時にモデルをストアに割り当てるにはどうすればよいですか?

4

1 に答える 1

1
constructor: function(config) {
    var me = this;

    if (config.listUrl) {
        me.proxy.url = config.listUrl;
    }
    me.callParent();

    if (config.extraFields) {
        me.model.setFields(config.extraFields);
    }

    //If the URL is present, load() the store.
    if (me.proxy.url) {
        me.load();
    }
}

store: Ext.create('DropDownStore', {
    listUrl: 'someprivateurl',
    extraFields: [
        { name: 'Id', type: 'int' },
        { name: 'RelationName', type: 'string' },
        { name: 'RelationOppositeName', type: 'string' }
    ]
}),
于 2013-03-19T16:09:42.603 に答える