li975571839 2015-07-27 10:39 采纳率: 100%
浏览 2499
已采纳

Extjs4使用mvc模式,封装Store层的ArrayStore无法动态加载后台数据

store层代码

 Ext.define('Desktop.store.function.FunctionStore',{
    extend: 'Ext.data.ArrayStore',
    requires:['Desktop.model.function.UserModel'],
    model: 'Desktop.model.function.UserModel',
    autoLoad: true,
    proxy:{
        type:'ajax',
        url:'index/userFindAll.do',
        reader: {
            type: 'json'
        }
    }
});

view层代码

 Ext.define('Desktop.view.function.FunctionGrid', {
    extend: 'Ext.panel.Panel',
    requires: ['Desktop.store.function.FunctionStore'],
    alias: 'widget.itgrid',
    itemId: 'sampleTest',
    layout: {
        type: 'border'
    },
    title: '表单',
    initComponent: function() {
        var me = this;
        var store = Ext.create('Desktop.store.function.FunctionStore');
        store.load();
//        var store = Ext.create('Ext.data.ArrayStore',{
//          model:'Desktop.model.function.UserModel',
//          proxy:{
//              type:'ajax',
//              url:'index/userFindAll.do'
//          }
//        });
//        store.load();
        //声明行编辑器插件
        var rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
            clicksToMoveEditor: 1,
            autoCancel: false
        });
        //复选框插件
        var sm = Ext.create('Ext.selection.CheckboxModel');
        Ext.applyIf(me, {
            items: [{
                id:'itl',
                xtype:'gridpanel',
                bodyPadding: 0,
                region: 'center',
                columns: [{
                    text: 'id',
                    width: 97,
                    sortable: true,
                    renderer: this.change,
                    dataIndex: 'id'
                },{
                    text: 'groupId',
                    width: 97,
                    sortable: true,
                    renderer: this.pctChange,
                    dataIndex: 'groupId'
                },{
                    text: 'userName', 
                    locked: true,
                    width: 200,
                    sortable: false,
                    dataIndex: 'userName'
                },{
                    text: 'userPass',
                    width: 97,
                    sortable: false,
                    dataIndex: 'userPass'
                },{
                    text: 'userDes',
                    width: 97,
                    sortable: false,
                    dataIndex: 'userDes'
                },{
                    text: 'modifyTime',
                    width: 97,
                    sortable: false,
                    dataIndex: 'modifyTime'
                },{
                    text: 'userPass',
                    width: 97,
                    sortable: false,
                    dataIndex: 'userPass'
                },{
                    text: 'userDes',
                    width: 97,
                    sortable: false,
                    dataIndex: 'userDes'
                },{
                    text: 'modifyTime',
                    width: 97,
                    sortable: false,
                    dataIndex: 'modifyTime'
                },{
                    text: 'userPass',
                    width: 97,
                    sortable: false,
                    dataIndex: 'userPass'
                },{
                    text: 'userDes',
                    width: 97,
                    sortable: false,
                    dataIndex: 'userDes'
                },{
                    text: 'userPass',
                    width: 97,
                    sortable: false,
                    dataIndex: 'userPass'
                },{
                    text: 'userDes',
                    width: 97,
                    sortable: false,
                    dataIndex: 'userDes'
                }],
                store: store,
                selModel: sm
            }]
        }); 
        me.callParent(arguments);
    },

    change: function (val) {
        if (val > 0) {
            return '<span style="color:green;">' + val + '</span>';
        } else if (val < 0) {
            return '<span style="color:red;">' + val + '</span>';
        }
        return val;
    },
    pctChange: function (val) {
        if (val > 0) {
            return '<span style="color:green;">' + val + '%</span>';
        } else if (val < 0) {
            return '<span style="color:red;">' + val + '%</span>';
        }
        return val;
    }

});
  • 写回答

2条回答 默认 最新

  • li975571839 2015-07-27 12:22
    关注

    还是自己回答吧,没有悬赏的分。。
    我发现把extend:继承的ArrayStore改成Store就好了,具体原因没时间研究,刚学了两个星期,工作需要不得不先做。同时我还发现了extjs4版本的gridpanel中tabpanel中嵌入gridpanel,如果多列,同时设置某列locked,就会出现格式错位,后来使用Store就没有这个问题了,不知道为什么ArrayStore会有这个问题。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果