zoukankan      html  css  js  c++  java
  • EXTJS 4.2 资料 控件之 Store 用法

    最近工作,发现在Extjs中自定义Store的功能挺多,特意在此做笔记,几下来,具体代码如下:

    1.定义Store

    //定义Store
    
    var ItemSelectorStore = new Ext.data.ArrayStore({
        fields: [
            { name: 'BaseInfoId' },
            { name: 'Title' }
        ]
    });

    2.根据Grid的数据,循环往Store里面插

      var selectedData = InfoCollectionGrid.getSelectionModel().getSelection();
            if (selectedData.length < 1) {
                Ext.MessageBox.alert('提示', '请选择要批量移动的记录!'); return;
            }
            else {
                ItemSelectorFormWin_Move.show();
                ItemSelectorFormWin_Move.setTitle("批量移动");
                ItemSelectorStore.removeAll();
                ItemSelectorStore_MoveDele.removeAll();
    
                for (var i = 0; i < selectedData.length; i++) {
                    ItemSelectorStore.insert(i, { InfoCollectionId: selectedData[i].data.InfoCollectionId, Title: selectedData[i].data.Title });//插入到最后一行
                    ItemSelectorStore_MoveDele.insert(i, { InfoCollectionId: selectedData[i].data.InfoCollectionId });//插入到最后一行
                }
    
                document.getElementById('howMany_Move').innerText = "共选择了" + selectedData.length + "篇文章";
            }

    3.循环读取Store中某行某列的数据

        for (var i = 0; i < ItemSelectorStore.getCount() ; i++) {
                        var record = ItemSelectorStore.getAt(i);
                        StrBaseInfoId += record.get("BaseInfoId") + ',';
                    }

    上面这是获取的是列:BaseInfoId的数据。

    4.移除grid中某行的数据(静态删除数据)

    FunctionActionDelete_StyleFiles = function () {
        if (gridJSFiles.getSelectionModel().getSelection()[0] == null) {
            Ext.MessageBox.alert('提示', '请选择要删除的记录吗!'); return;
        }
        var selectedData = gridJSFiles.getSelectionModel().getSelection()[0].data;
    
        Ext.Msg.confirm("提示!", "确定要删除的记录吗?", function (btn) {
            if (btn == "yes") {        
                var sm = gridJSFiles.getSelectionModel();
                var store = gridJSFiles.getStore();
                store.remove(sm.getSelection());
                if (store.getCount() > 0) {
                    sm.select(0);
                }
            }
            else { return; }
        });
    }

     5.移除grid中某行的数据(动态删除数据)

        FunctionActionDelete = function () {
    
            if (grid.getSelectionModel().getSelection()[0] == null) {
                Ext.MessageBox.alert('提示', '请选择要删除的记录吗!'); return;
            }
            var selectedData = grid.getSelectionModel().getSelection()[0].data;
            Ext.Msg.confirm("提示!", "确定要删除的记录吗?", function (btn) {
                if (btn == "yes") {
                    Ext.MessageBox.show({
                        msg: '正在删除,请稍等...',
                        progressText: 'Saving...',
                         300,
                        wait: true,
                        waitConfig: { interval: 200 }
                    });
                    setTimeout(function () { }, 1000);
                    Ext.Ajax.request({
                        url: '/UI/HttpHandlerData/JDQP/JDQP.ashx?operation=DeleCarPartsType',
                        method: "POST",
                        params: {
                            CSId: selectedData.CSId
                        },
                        success: function (response) {
                            Ext.MessageBox.alert('提示', '删除成功!');
                            store.load({ params: { start: start, limit: limit } });
                            Ext.MessageBox.hide();
                        },
                        failure: function (errorInfo) {
                            Ext.MessageBox.alert("提示", "删除失败!<br>" + errorInfo.responseText);
                        }
                    });
                }
            });
        }
  • 相关阅读:
    如何评测软件工程知识技能水平?
    创新产品的需求分析:未来的图书会是什么样子?
    案例分析:设计模式与代码的结构特性
    业务领域建模Domain Modeling
    转载:10 Easy Steps to a Complete Understanding of SQL
    二十六个月Android学习工作总结
    android sdk无法更新问题解决
    android中利用view画出一条竖线
    android-Java SoftReference,WeakReference,Direct Reference简介
    Intellij IDEA开发第一个android应用教程
  • 原文地址:https://www.cnblogs.com/foreverfendou/p/4192877.html
Copyright © 2011-2022 走看看