Javascript ExtJS-3、Ext.grid.GridPanel、多行复选框:如何一次提交所有选中项?

Javascript ExtJS-3、Ext.grid.GridPanel、多行复选框:如何一次提交所有选中项?,javascript,forms,extjs,multi-select,Javascript,Forms,Extjs,Multi Select,我使用的是ExtJS3,我有一个Ext.grid.GridPanel,其中每一行的左边都有一个复选框。顶部有两个按钮:“刷新”和“提交”。我希望能够选择多个行,并在一次提交按钮点击提交他们所有。现在,当我选择多行并点击submit时,它将提交第一行,然后从网格中删除该项,我必须再次点击submit(以前选中的行仍处于选中状态) 如何更改以下代码以使submit按钮一次发送所有行 var dataStore = new Ext.data.SimpleStore({ fields: [

我使用的是ExtJS3,我有一个Ext.grid.GridPanel,其中每一行的左边都有一个复选框。顶部有两个按钮:“刷新”和“提交”。我希望能够选择多个行,并在一次提交按钮点击提交他们所有。现在,当我选择多行并点击submit时,它将提交第一行,然后从网格中删除该项,我必须再次点击submit(以前选中的行仍处于选中状态)

如何更改以下代码以使submit按钮一次发送所有行

var dataStore = new Ext.data.SimpleStore({   fields: [
        {name: 'node'},
        {name: 'ip'},
        {name: 'groups'}
        ]});
var checkBoxSelMod = new Ext.grid.CheckboxSelectionModel();
var dataGrid = new Ext.grid.GridPanel ({
renderTo: document.body,
   clickstoEdit: 2,
   selModel : checkBoxSelMod,
   xtype: 'grid',
   layout: 'fit',
   sm: new Ext.grid.CheckboxSelectionModel(),
   tbar: [
          {
          text: 'Refresh',
              icon:    '$nroot/includes/extjs3/resources/images/slate/button/table_refresh.png',
              cls: 'x-btn-text-icon',
              handler: function() {
              window.location = '$nroot/index.php/imaging/index';},
              scope: this,
              },
          {
          text: 'Submit Machine(s)',
              icon: '$nroot/includes/extjs3/resources/images/slate/button/table_add.png',
              cls: 'x-btn-text-icon',
              handler: function() {
              var sm = dataGrid.getSelectionModel();
              var sel = sm.getSelected();
              if (sm.hasSelection()) {


                Ext.Msg.show({
                  title: 'Image Machine?',
                      buttons: Ext.MessageBox.YESNO,
                      msg: 'Continue with imaging (no undo!) process for server: '+sel.data.node+'?',
                      fn: function(btn){
                      if (btn == 'yes'){
                        var conn = new Ext.data.Connection();
                        conn.request({
                          url: '$nroot/index.php/imaging/image/',
                              params: {
                            action: 'delete',
                                node: sel.data.node,
                                mgmtip: sel.data.ip
                                },                            
                              success: function(resp,opt) {
                              dataGrid.getStore().remove(sel);
                            },
                              failure: function(resp,opt) {
                              Ext.Msg.alert('Error','Unable to image server - check debug logs');
                            }
                          });
                      }
                    }
                  });
              }
            }
          }               
          ],
   store: dataStore,
   columns: [                  
             checkBoxSelMod,
             { id: 'node', header: "Node", width: 150, sortable: true, dataIndex: 'node'},
             { id: 'ip', header: "IP", width: 120, sortable: false, dataIndex: 'ip'},
             { id: 'groups', header: "Groups", width: 100, sortable: true, dataIndex: 'groups'},
             ],
   stripeRows: true,
   autoExpandColumn: 'node',
   listeners: { 
 render: function(){ this.store.loadData(dataList); }
     }      
})});
当我将代码从getSelected更改为getSelections时,它会在页面加载时返回以下内容:

item type is invalid for AcceptItem action
我找不到任何显示multi-select with submit for GridPanels的示例。有我可以参考的吗

编辑,基于以下解决方案,我修改了代码,如下所示:

              var sels = sm.getSelections();
              if (sels.length > 0) {
                var ips = [], nodes = [];
                Ext.each(sels, function(sel) {
                           ips.push(sel.get('ip'));
                           nodes.push(sel.get('node'));
                         });

                Ext.Msg.show({
                  title: 'Image Machine?',
                      buttons: Ext.MessageBox.YESNO,
                      msg: 'Continue with imaging (no undo!) process for servers: '+nodes.join(",")+'?',
                      fn: function(btn){
                      if (btn == 'yes'){
                        Ext.each(sels, function(sel) {
                                   var conn = new Ext.data.Connection();
                                   conn.request({
                                     url: '$nroot/index.php/imaging/image/',
                                         params: {
                                       node: sel.get('node'),
                                           mgmtip: sel.get('ip')
                                           },                            
                                         success: function(resp,opt) {
                                         dataGrid.getStore().remove(sel);
                                       },
                                         failure: function(resp,opt) {
                                         Ext.Msg.alert('Error','Unable to image server - check debug logs');
                                       }
                                     });
                                 })
                          }
                    }
                  });
              }
            }

最简单的方法是循环浏览选定的记录,并针对每个记录询问一个问题

var sels = sm.getSelections();
Ext.each(sels, function(sel) {
    var node = sel.get('node'),
        ip = sel.get('ip');
    Ext.Msg.show({
        title: 'Image Machine?',
        buttons: Ext.MessageBox.YESNO,
        msg: 'Continue with imaging (no undo!) process for server: '+node+'?',
        fn: function(btn){
            if (btn == 'yes'){
                var conn = new Ext.data.Connection();
                conn.request({
                    url: '$nroot/index.php/imaging/image/',
                    params: {
                        action: 'delete',
                        node: node,
                        mgmtip: ip
                    },                            
                    success: function(resp,opt) {
                        dataGrid.getStore().remove(sel);
                    },
                    failure: function(resp,opt) {
                        Ext.Msg.alert('Error','Unable to image server - check debug logs');
                    }
                });
            }
        }
    });
});
但是,对于用户来说,在DataGrid中为每一行选择一个提示可能并不好。但是,如果您的服务(“$nroot/index.php/imaging/image/”)支持发布多个项目,您可以一次性询问用户并发布所有项目。即

var sels = sm.getSelections();
if (sels.length > 0) {
    var ips = [], nodes = [];
    Ext.each(sels, function(sel) {
        ips.push(sel.get('ip'));
        nodes.push(sel.get('node'));
    });

    Ext.Msg.show({
        title: 'Image Machine?',
        buttons: Ext.MessageBox.YESNO,
        msg: 'Continue with imaging (no undo!) process for servers: '+nodes.join(",")+'?',
        fn: function(btn){
            if (btn == 'yes'){
                var conn = new Ext.data.Connection();
                conn.request({
                    url: '$nroot/index.php/imaging/image/',
                    params: {
                        action: 'delete',
                        nodes: nodes,
                        mgmtips: ips
                    },                            
                    success: function(resp,opt) {
                        Ext.each(sels, function() { dataGrid.getStore().remove(this) });
                    },
                    failure: function(resp,opt) {
                        Ext.Msg.alert('Error','Unable to image server - check debug logs');
                    }
                });
            }
        }
    });
}

我最后修改了你的第二个解决方案。