【问题标题】:Event handler for checkbox / dojox.grid.cells.Bool in a ItemFileWriteStore in EnhancedGrid?增强网格中 ItemFileWriteStore 中复选框/dojox.grid.cells.Bool 的事件处理程序?
【发布时间】:2013-09-15 16:55:07
【问题描述】:

我有一个由 ItemFileWriteStore 填充的增强网格。商店中的一项数据是:

check: true

然后在增强的网格中我有:

{
   field: "check",
   name: "Value Check",
   editable: true,
   type: dojox.grid.cells.Bool
}

这给了我一个充满复选框的列。我一直无法找到如何处理检查这些复选框。我想从选中每个复选框开始,如果您取消选中一个,它会删除相应的数据。是否有一些事件处理程序可以附加到dojo/on?或者我不知道的增强网格上的一些方法?我找不到任何关于此的文档,我觉得我错过了一些东西。

【问题讨论】:

    标签: javascript event-handling dojo dojox.grid


    【解决方案1】:

    你会做这样的事情::

    require(['dijit/registry','dojo/on','dijit/WidgetSet','dojo/on'],function(reg,on){
        reg.byClass("dojox.grid.cells.Bool").forEach(function(node){
                       on(node.domNode,'click',function(){alert('hello');});
         });
    
    });
    

    【讨论】:

    • 这对我不起作用,不知道为什么。但我会发布我提出的解决方案。
    【解决方案2】:

    我发现最好的解决方案是将处理程序附加到“RowClick”事件,因为每次单击复选框时,都会触发 RowClick 事件。然后遍历数据存储并根据复选框更新所有内容。它绝对不是有效的,但可以满足我的需要。是这样的:

    grid.on("RowClick", function (event) {
      for (var i=0; i<store._arrayOfAllItems.length; i++) {
        if (grid.getItem(i)) {
          if (grid.getItem(i).check[0]) {
            // row is checked, do something
          } else {
            // row is not checked, do something else
          }
        }
      }
    } 
    

    据我所知,event 没有传递有助于识别网格中哪一行被点击的信息(我不能 100% 确定,其中有很多内容)。所以这是我想出的最好方法。

    【讨论】:

      【解决方案3】:
             {
                  name: 'Paid',
                  field: 'paid',
                  width: '40px',
                  type: dojox.grid.cells.Bool,
                  editable:true,
                  doclick:function(e){
                      if(e.target.tagName == 'INPUT'){
                          if(confirm("Sure?")){
                              this.applyStaticValue(e.rowIndex);
                          } else {
                              e.target.checked = !e.target.checked;
                          }
                      }
                  }
              }
      

      这是一个老问题,我在这里用谷歌搜索。 希望我的回答可以帮助到别人。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-06-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-04-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多