使用Ext.data.Model时,url未定义

时间:2012-07-31 14:51:58

标签: extjs4.1

我正在一个小项目中工作,我想使用ext.data.model,当我想加载一些数据时,我遇到了一些问题。

这是模型声明。

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
        }
    }
});

我将它与这样的jsonstore一起使用。

new Ext.data.JsonStore({
                    storeId: 'mainStore',
                    autoLoad: true,
                    model: 'Model.Item'
                })
在我没有使用模型之前,用网格绑定它,并且工作得很好。不,我不能让它工作。

我在ur-all.js

中获取url是未定义的异常
    urlAppend : function(url, string) {
        if (!Ext.isEmpty(string)) {
            return url + (url.indexOf('?') === -1 ? '?' : '&') + string;
        }


        return url;
    },

这个函数是从buildUrl函数中的Ext.data.proxy.Server调用的。

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:2)

使用JsonStore覆盖模型的代理定义 - JsonStore添加自己的代理配置:

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]);
    }
});

如果商店存在这种情况,则不会在模型中查找。

要解决此问题,请将Ext.data.JsonStore替换为Ext.data.Store