Extjs使用商店代理api; CRUD

时间:2012-02-04 00:38:34

标签: extjs crud

您好我试图实现writer.js并且我收到错误: 未捕获的TypeError:对象#没有方法'read'

这是我的代码片段,非常感谢您对此问题的任何帮助:

Ext.onReady(function(){

var store = Ext.create('Ext.data.Store', {
    model: 'User',
    autoLoad: true,
    autoSync: true,
    proxy: {
        type: 'ajax',
        api: {
            read: '/orm_2/view/user/app/remote/app/controllers/users.php?action=view',
            create: '/orm_2/view/user/app/remote/app/controllers/users.php?action=create',
            update: '/orm_2/view/user/app/remote/app/controllers/users.php?action=update',
            destroy: '/orm_2/view/user/app/remote/app/controllers/users.php?action=destroy'
        },
        reader: {
            type: 'json',
            successProperty: 'success',
            root: 'USERS',
            messageProperty: 'message'
        },
        writer: {
            type: 'json',
            writeAllFields: true,
            root: 'USERS'
        },
        listeners: {
            exception: function(proxy, response, operation){
                Ext.MessageBox.show({
                    title: 'REMOTE EXCEPTION',
                    msg: operation.getError(),
                    icon: Ext.MessageBox.ERROR,
                    buttons: Ext.Msg.OK
                });
            }
        }
    },
    listeners: {
        write: function(proxy, operation){
            if (operation.action == 'destroy') {
                main.child('#form').setActiveRecord(null);
            }
            Ext.example.msg(operation.action, operation.resultSet.message);
        }
    }
});

var main = Ext.create('Ext.container.Container', {
    padding: '0 0 0 20',
    width: 500,
    height: 450,
    renderTo: document.body,
    layout: {
        type: 'vbox',
        align: 'stretch'
    },
    items: [{
        itemId: 'form',
        xtype: 'writerform',
        height: 150,
        margins: '0 0 10 0',
        listeners: {
            create: function(form, data){
                store.insert(0, data);
            }
        }
    }, {
        itemId: 'grid',
        xtype: 'writergrid',
        title: 'User List',
        flex: 1,
        store: 'UserStore',
        listeners: {
            selectionchange: function(selModel, selected) {
                main.child('#form').setActiveRecord(selected[0] || null);
            }
        }
    }]
});
});

2 个答案:

答案 0 :(得分:0)

当我在加载商店之前没有初始化我的模型时遇到了这个错误。所以在我的情况下,做一个Ext.create('my.model')或将我的模型添加到requires属性修复了这个错误:

  

“Uncaught TypeError:Object#没有方法'read'”。

看起来您的模型被称为“用户”,就在您创建商店之前进行此调用:

Ext.create('User');

答案 1 :(得分:-3)

Ext.define('User', {
    extend: 'Ext.data.Model',
    fields: [some fields]
});

Extjs 4.1