url indefinido al usar Ext.data.Model

i'm working in a small project and i want to use the ext.data.model, the thing is that i having some problems when i want to load some data.

here is the model declaration.

Ext.define('Model.Item',{
    extend: 'Ext.data.Model',
    fields: ['id', 'code', 'description'],


    proxy: {
        type: 'ajax',
        api: {
            read: 'Handlers/Item.ashx',
            create: 'Handlers/Item.ashx?action=create',
            destroy: 'Handlers/Item.ashx?action=delete',
            update: 'Handlers/Item.ashx?action=update'
        },
        reader: {
            type: 'json',
            root: 'items'
        },
        writer: {
            type: 'json',
            writeAllFields: true,
            root: 'data',
            allowSingle: false
        }
    }
});

and i using it with a jsonstore like this.

new Ext.data.JsonStore({
                    storeId: 'mainStore',
                    autoLoad: true,
                    model: 'Model.Item'
                })

binging it with a grid, before i wasnt using model, and was working just fine. no i cant get it to work.

i get url is undefined exception in ext-all.js

    urlAppend : function(url, string) {
        if (!Ext.isEmpty(string)) {
            return url + (url.indexOf('?') === -1 ? '?' : '&') + string;
        }


        return url;
    },

this funcion is called from Ext.data.proxy.Server in the buildUrl function.

well any help would be appreciated.

preguntado el 31 de julio de 12 a las 15:07

Possibly by using JsonStore you are overriding the proxy definition of your model - JsonStore adds its own proxy config, and if such exist for the store it won't look for one in the model. Try replacing Ext.data.JsonStore con Ext.data.Store. -

i have not declared a proxy in the jsonstore. but debugging extjs i found that the store loads as this.proxy.read(xxx) instead of search for me.model.proxy (if exists)... -

If I understand you correctly then yes - JsonStore automatically adds a proxy, which was called instead of that of the model. So is your problem solved? -

not yet... i want to define the proxy in the model.. as it is exposed in the doc... -

Y usando Ext.data.Store no ayuda? -

1 Respuestas

Mediante el uso JsonStore you are overriding the proxy definition of your model - JsonStore adds its own proxy config:

Ext.define('Ext.data.JsonStore',  {
    extend: 'Ext.data.Store',
    alias: 'store.json',

    …

    constructor: function(config) {
        config = Ext.apply({
            proxy: {
                type  : 'ajax',
                reader: 'json',
                writer: 'json'
            }
        }, config);
        this.callParent([config]);
    }
});

and if such exist for the store it won't look for one in the model.

Para solucionar esto, reemplace Ext.data.JsonStore con Ext.data.Store.

Respondido 01 ago 12, 15:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.