2016-05-12 62 views
0

我正在使用IBM Content Navigator 2.0.3,它使用DOJO 1.8进行GUI开发。我是dojo中的新成员,我必须增强其中一种形式:向dataGrid添加事件处理程序,以便在选中某个网格的某一行时启用其中一个按钮。 我已经设法添加事件处理程序,正如在这个问题中建议的:dojo datagrid event attach issue 但我仍然无法启用按钮。这里是形式的HTML:通过事件处理程序的Dojo启用按钮

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

所附的图像描述它的外观enter image description hereenter image description here 而postCreate功能的js文件的代码如下:

postCreate: function() { 
     this.inherited(arguments); 
     this.textDir = has("text-direction"); 

     domClass.add(this._selectedDataGridContainer, "hasSorting"); 
     this._renderSelectedGrid(); 

     this.own(aspect.after(this.addUsersButton, "onClick", lang.hitch(this, function() { 
      var selectUserGroupDialog = new SelectUserGroupDialog({queryMode:"users", hasSorting:true, callback:lang.hitch(this, function (user) { 
       this._onComplete(user); 
       this._markDirty(); 
      })}); 
      selectUserGroupDialog.show(this.repository); 
     }))); 

     this.own(aspect.after(this.removeUsersButton, "onClick", lang.hitch(this, function() { 
      if (this._selectedGrid != null) { 
       var selectedItems = this._selectedGrid.selection.getSelected(); 
       if (selectedItems.length > 0) { 
        array.forEach(selectedItems, lang.hitch(this, function(item) { 
         this._selectedGrid.store.deleteItem(item); 
        })); 
       } 
       this._selectedGrid.selection.clear(); 
       this._selectedGrid.update(); 
      } 
      this._markDirty(); 
     }))); 

// the following handler was added by me 
     dojo.connect(this.myGrid, 'onclick', dojo.hitch(this, function(){ 
      console.log(" before "); 
     this.removeUsersButton.set('disabled', true); 
      console.log(" after "); 
     })); 

    }, 

所以this.own(aspect.after(this.removeUsersButton .....工作正常,我的干涉工作之前那么它在某种程度上可访问此。 .removeUsersButton并处理事件,但是我的处理程序dojo.connect(this.myGrid ....只打印console.log()前后没有启用Remove按钮。Button没有Id,只有data-dojo-attach-点。当daaGrid被选中时,如何启用Remove按钮?

回答

1

使用this.removeUsersButton.set('disabled',true);你正在设置要禁用的按钮,如果你想启用它,你需要设置它假。

this.removeUsersButton.set('disabled', false); 
+0

AAAA!我做了一个简单的错误!非常感谢 !!! )) –

+0

之后我必须断开处理程序吗?如果是的话,我应该在哪里放这个代码? –

+0

不需要,它取决于事件内的实现。如果你正在更新某些东西,那么你将不得不思考。如果它只是启用一个按钮,那就OK了。由于再次设置不会改变任何内容。如果你想要一些事件只能工作一次,那么你应该使用“on.once”。 –