EXTJS 4.2 资料 控件之 Store 用法

时间:2021-01-14 04:01:53

最近工作,发现在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 = ; i < ItemSelectorStore.getCount() ; i++) {
var record = ItemSelectorStore.getAt(i);
StrBaseInfoId += record.get("BaseInfoId") + ',';
}

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

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

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