2 peipei078 peipei078 于 2013.07.22 20:36 提问

Extjs中store问题,通过id,从后台查数据存入store中,并在panel中显示

//创建model
Ext.regModel('rukuInfos',{
fields:[{name:'id'},{name: 'rukuRemark'},{name:'rukuAcount'},{name:'rukuDateTime'},{name:'rukuId'}]
});

//有问题的方法
function showruku(){

           var rukustore = Ext.create('Ext.data.Store', {

            pageSize: 6,  //分页大小
            model: 'rukuInfos',
            proxy: {
                pageParam:'pageNo',
               type: 'ajax',
                 method: 'POST',
               url: 'http://localhost:8000/medicine/ProductAction_queryRukuInfo.action' ,//请求的地址
                reader: { root: 'rukuInfos', totalProperty: 'rowCount' }

            }
        });//


     var rukuGrid = Ext.create('Ext.grid.Panel', {

            title: '药品入库信息列表',

            width: 520,
            height:230,
            id:'rukuGrid',

            store: rukustore,

            region: 'center',
            loadMask: true, //加载提示{ msg: '正在加载数据,请稍侯……' }

            columns: [//配置表格列

            Ext.create('Ext.grid.RowNumberer', {text : '行号', width : 40}),
                  {header: "入库编号", width: 160, dataIndex: 'rukuId'},
                                        {header: "入库时间", width: 100, dataIndex: 'rukuDateTime' ,
                                            xtype : 'datecolumn',//Ext.grid.column.Date日期列
                                            format : 'Y-m-d'//日期格式化字符串
                                            },
                                        {header: "入库数量", width: 100, dataIndex: 'rukuAcount', 
                                            xtype: 'numbercolumn',
                                            format:'000.0'
                                            },
                                        {header: "入库备注", width: 120, dataIndex: 'rukuRemark'}
                                        ],

            dockedItems: [
            {
                xtype: 'pagingtoolbar',
                store: rukustore,  // same store GridPanel is using
                dock: 'bottom', //分页的位置
                emptyMsg: '没有数据',
                displayInfo: true,
                displayMsg: '当前显示{0}-{1}条记录 / 共{2}条记录 ',
                beforePagetext: '第',
                afterPagetext: '页/共{0}页'
            }]

        });

        //初始加载第1页
        rukustore.loadPage(1);

        var winruku= new Ext.window.Window({
        layout:'fit',
        width:535,
        resizable : false,
        shadow : true,
        modal :true,
         plain: true, 
         disabled : false,
        closable:true,
        items:rukuGrid
    });


        var proList = getProductIdList();
        var num = proList.length;
        if(num > 1){
            Ext.MessageBox.alert("提示","每次只能查看一条药品的入库信息。");
        }else if(num == 1){
        winruku.setTitle("显示该药品入库信息");
            winruku.show();
            var id = proList[0];
        alert(id);


         //从后台加载数据
     Ext.Ajax.request({//如果报length为空,一般要新建一个model来弄

        url : 'http://localhost:8000/medicine/ProductAction_queryRukuInfo.action' ,
        method : 'get',
       params : {proid:id},
       jsonData : {
            proid:id

        },

       success : function(response)
        {
            var data = Ext.JSON.decode(response.responseText).rukuInfos;

            var json = eval("(" + response.responseText + ")");

            rukucunstore = new Ext.data.Store(

            {
                model : 'rukuInfos',
                proxy : {
                 pageParam:'pageNo',
                   type : 'memory',

                    reader : {
                        type : 'json',
                        root:'rukuInfos'//注意mode1的值一定要与后台的一致

                    }
                }
            });

            rukucunstore.load(data);
            Model = rukucunstore.Model;
            alert(rukucunstore.data);

       }

  });

        }   


    //取得所选药品id
    function getProductIdList(){

        var recs = proGrid.getSelectionModel().getSelection();
        var list = [];
        if(recs.length == 0){
            Ext.MessageBox.alert('提示','请选择要进行操作的药品!');
        }else{
            for(var i = 0 ; i < recs.length ; i++){
                var rec = recs[i];
                list.push(rec.get('id'));

            }
        }
        return list;
    }
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!