Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ExtJs:确定在存储上触发更新事件的网格_Javascript_Extjs - Fatal编程技术网

Javascript ExtJs:确定在存储上触发更新事件的网格

Javascript ExtJs:确定在存储上触发更新事件的网格,javascript,extjs,Javascript,Extjs,我在ExtJs 3.3.1中使用了livegrid,但我相信这个问题对ExtJs来说是全局性的。 存储上的侦听器如何知道事件来自哪个网格 这里是为什么和一些代码 我在存储上有一个侦听器,在更新时,我想知道在网格中选择了哪些行,并挂起事件。这样我就可以在网格中进行选择,更新该范围内的字段,并在整个选择中更新该字段。选择不带复选框,只需突出显示行即可完成。因为这个监听器被许多网格使用,所以我需要一种方法从gridlistener获得的参数中获取它,但这只是存储、记录和操作 Ext.override(

我在ExtJs 3.3.1中使用了livegrid,但我相信这个问题对ExtJs来说是全局性的。 存储上的侦听器如何知道事件来自哪个网格

这里是为什么和一些代码

我在存储上有一个侦听器,在更新时,我想知道在网格中选择了哪些行,并挂起事件。这样我就可以在网格中进行选择,更新该范围内的字段,并在整个选择中更新该字段。选择不带复选框,只需突出显示行即可完成。因为这个监听器被许多网格使用,所以我需要一种方法从gridlistener获得的参数中获取它,但这只是存储、记录和操作

Ext.override(Ext.ux.grid.livegrid.Store, {
    listeners: {
      'update': function(store, record, action) {
        if (action=='commit'){ //each update has 2 actions, an edit and a commit
          var selected = grid.getSelectionModel().getSelections();  //need to know which grid
          if (selected.length>1){ //if more than one row selected
            grid.suspendEvents();
            store.writer.autoSave = false;
            for(var i=0; i < selected.length; i++){
              if (this.fieldChanged) {
                for (var name in this.fieldChanged) { 
                  //get the field changed and update the selection with the value
                  if (selected[i].get(name)!=this.fieldChanged[name]){
                    selected[i].set(name, this.fieldChanged[name]);
                  }
                } 
              }
            }
            grid.resumeEvents();
            store.fireEvent("datachanged", store);
            store.writer.autoSave = true;
          }
        }
        if (action=='edit'){
          this.fieldChanged = record.getChanges()
        }
      }
    }
  });
Ext.override(Ext.ux.grid.livegrid.Store、{
听众:{
“更新”:函数(存储、记录、操作){
if(action=='commit'){//每个更新有两个操作,一个编辑操作和一个提交操作
var selected=grid.getSelectionModel().getSelections();//需要知道哪个网格
if(selected.length>1){//如果选择了多行
网格。吊杆();
store.writer.autoSave=false;
对于(变量i=0;i
我自己找到了一个解决方案,我覆盖了livegrid,在它的存储中包含了对自身的引用,就像这样

Ext.override(Ext.ux.grid.livegrid.EditorGridPanel, {
    listeners: {
      'afterrender': function(self) {
        this.store.grid = this.id;
      }
    }
  });

然后在我的store listener中,我可以引用store.grid,这在扩展中会更容易,但也可以在覆盖中完成

MyGridPanel = Ext.extend(Ext.ux.grid.livegrid.EditorGridPanel, { 
    initComponent: function(){  
        MyGridPanel.superclass.initComponent.call(this);
        this.store.grid = this;
    }
});
编辑---显示如何在覆盖中进行编辑,它并不漂亮,但很有用

var oldInit = Ext.ux.grid.livegrid.EditorGridPanel.prototype.initComponent;
Ext.override(Ext.ux.grid.livegrid.EditorGridPanel, {
    initComponent: function(){
        oldInit.call(this);
        this.store.grid = this;
    }
});

可能会有更多的网格使用存储。最好在Ext Js 4中观察Gridpanel类,如下所示:

//Associate all rendered grids to the store, so that we know which grids use a store.
Ext.util.Observable.observe(Ext.grid.Panel);
Ext.grid.Panel.on('render', function(grid){
    if (!grid.store.associatedGrids){
        grid.store.associatedGrids=[];
    }
    grid.store.associatedGrids.push(grid);
});

你到底想完成什么?网格应该自动更新其内容。你的问题不清楚真正的问题是什么,我使用这个监听器处理很多网格,我需要知道监听器本身在处理哪个网格,我明白这一点。你到底想在听众中做什么?看起来您正在手动更新网格,这应该会自动发生耶…不,用户希望用相同的字段值填充多行,因此他选择行,只编辑一个字段,其余选定行也将替换为该字段中的该值,这项工作现在开始了,因为我知道我正在使用哪个网格,但这项工作应该适用于所有网格。但是,是的,那么您需要知道在网格中选择了什么。但这应该是网格处理程序,不是吗?为什么要在商店级别上这样做?直接在原型上添加侦听器是不好的做法。Ie:var grid=new Ext.ux.grid.livegrid.EditorGridPanel({listeners:{'afteredit':function(){}})将清除afterrender侦听器。但是我必须在我的所有网格上这样做,不是吗?