【问题标题】:dojo datagrid event attach issuedojo datagrid 事件附加问题
【发布时间】:2016-09-07 23:51:06
【问题描述】:

我正在使用 IBM Content Navigator 2.0.3,它使用 DOJO 1.8 进行 GUI 开发。我是 dojo 的新手,我必须增强其中一种形式:向dataGrid 添加一个事件处理程序,以便在选择网格行时启用其中一个按钮。

dataGrid在HTML中描述如下:

<div class="selectedGridContainer" data-dojo-attach-point="_selectedDataGridContainer">                     
    <div class="selectedGrid" data-dojo-attach-point="_selectedDataGrid" ></div>
</div>

而控制表单行为的JS文件只在_selectedDataGrid函数中提到了这个postCreate

postCreate: function() {
    this.inherited(arguments);
    this.textDir = has("text-direction");
    this.hoverHelpList = [];
    domClass.add(this._selectedDataGridContainer, "hasSorting");
    this._renderSelectedGrid();

_renderSelectedGrid() 正在执行,其中包含唯一提及:

_renderSelectedGrid: function() {
    .......
    this._selectedDataGrid.appendChild(this._selectedGrid.domNode); 

我尝试在 HTML 中添加一个 data-dojo-attach-event onRowClick: enableRemoveUsersButton 和一个

enableRemoveUsersButton: function(evt){
    this.removeUsersButton.set('disabled', true);
},

在 js 文件中。没有帮助。

然后我尝试了:

dojo.connect(myGrid, "onRowclick", function update() {
    this.removeUsersButton.set('disabled', true); });

但我无法使用以下方法获取 myGrid 对象:

`var myGrid  = dojo.byId("_selectedDataGrid");`

Can anyone tell me how to acquire the grid object and/or add an event handler to this grid, that fires when the row of the grid is selected?

谢谢!

【问题讨论】:

标签: events datagrid dojo


【解决方案1】:

从您的分享中,我可以看到节点“_selectedDataGrid”只是一个 Div 标记。并且您的 dataGrid 小部件可能是“this._selectedGrid”,因此您应该在该小部件而不是容器节点上添加事件。

还有 dijit.byId 来获取 dijit/widgets 的实例。 dojo.byId 用于搜索 dom 节点。

希望这对您有所帮助。

【讨论】:

  • 嗨。我已经设法在 this._selectedDataGrid 上添加了一个事件,但是当我单击网格的任何部分时会触发该事件,甚至没有选择一行。当我尝试进行检查时: var selectedItems = this._selectedDataGrid.selection.getSelected(); if (selectedItems.length > 0) {......什么都没有发生。
  • 可能你想使用 onSelected 或 onSelectionChanged 事件而不是 RowClick
【解决方案2】:

您将无法通过dojo.byId("_selectedDataGrid") 获取grid 对象。最好将myGrid 对象保留在类级别(小部件级别),并使用dojo.hitchconnect 保留。

dojo.connect(this.myGrid, 'onRowClick', dojo.hitch(this, function(){
        //access myGrid using this.myGrid and do the handling
}));

【讨论】:

  • 嗨。但是我在哪里可以获得 myGrid 作为您提供的功能的输入参数?
  • 无论您在何处创建grid 对象,都将其存储在this.myGrid 中。
  • 谢谢。我成功了。
猜你喜欢
  • 2011-08-20
  • 2012-08-03
  • 2011-08-02
  • 2013-11-15
  • 2010-11-15
  • 1970-01-01
  • 2012-10-14
  • 2013-01-18
  • 1970-01-01
相关资源
最近更新 更多