ExtJs批量更新

1年前 (2022) 程序员胖胖胖虎阿
143 0 0

昨天这个批量更新花了我不少时间,特记下来,省得以后忘记。

批量更新的逻辑是这样的。

获取Store中需要更新的行,把行放入数组,然后再将数组转化为Json字符串,Json字符串传后后台后,解析为实体列表,然后就遍历并批量更新啦。

批量更新主要代码如下:

1,获取Store更新行,批量提交到数据库。

                        //获取Store更新行,批量提交到数据库
                        var result = new Array();
                        for (var i = 0; i < wdpsDTOStore.data.length; i++) {
                            var model = wdpsDTOStore.getAt(i);
                            if (model.dirty) {
                                result.push(model.data);
                            }
                        }
                        if (result.length == 0) {
                            JsHelper.ShowError('修改行为空,请重新操作!');
                            return;
                        }

                        Ext.Ajax.request({
                            url: virupath + '/LogisticsMgr/UpdateWDps',
                            params: {
                                'strJsonWdps': Ext.encode(result)
                            },
                            success: function(form, action) {
                                var result = Ext.util.JSON
                                             .decode(form.responseText);                                
                                if (result.success) {
                                    JsHelper.ShowWarning('数据提交成功!');
                                    LoadStore();
                                } else {
                                    JsHelper.ShowError(result.msg);
                                }
                            },
                            failure: function(form, action) {                             
                                JsHelper.ShowError('提交异常,请稍后再试!');
                            }
                        });

2,在后台中解析并遍历。

            List<WdpsDTO> listWdpsDTO = FormatJsonExtension.JSONStringToList<WdpsDTO>(Request["strJsonWdps"]);
            foreach (WdpsDTO item in listWdpsDTO)
            {

            }        

 

现在看很简单,但当时走了一些弯路,不说了,但对我来说也是一个宝贵的经验。

 

版权声明:程序员胖胖胖虎阿 发表于 2022年11月25日 上午5:32。
转载请注明:ExtJs批量更新 | 胖虎的工具箱-编程导航

相关文章

暂无评论

暂无评论...