2017-10-08 70 views
3

我正在使用Dojo 1.8版。我设计了一个自定义小部件,如下所示。它的一个片段在DOJO中传递事件参数的正确方法是什么?

<div> 
 
\t <div> 
 
\t \t <input 
 
\t \t \t id ="NZ1", 
 
\t \t \t data-dojo-attch-point = "NZ1" 
 
\t \t \t data-dojo-attch-type = "ecm.widget.ValidationTextBox" 
 
\t \t \t data-dojo-attch-event = "onBlur : makeAllSmall" 
 
\t \t /> 
 
\t </div> 
 
\t <div> 
 
\t \t <input 
 
\t \t \t id ="NZ2", 
 
\t \t \t data-dojo-attch-point = "NZ2" 
 
\t \t \t data-dojo-attch-type = "ecm.widget.ValidationTextBox" 
 
\t \t \t data-dojo-attch-event = "onBlur: makeAllSmall" 
 
\t \t /> 
 
\t </div> 
 
</div>

这里是事件处理

makeAllSmall : function(evt){ 
 
\t var currVal=evt.target.value; 
 
\t currVal = currVal.toLowerCase(); 
 
\t /**Some Other business logic on currVal **/ 
 
}

EVT总是来为未定义。我对Dojo很陌生。我错过了HTML方面的东西吗?我试图如下更改HTML而不是运气

\t \t <input 
 
\t \t \t id ="NZ2", 
 
\t \t \t data-dojo-attch-point = "NZ2" 
 
\t \t \t data-dojo-attch-type = "ecm.widget.ValidationTextBox" 
 
\t \t \t data-dojo-attch-event = "onBlur : makeAllSmall" 
 
\t \t \t data-dojo-args="e" 
 
\t \t />

回答

1

第一件事,第一,有没有方法“onBlurr”一个错字?我看到有一个额外的'r'。它不应该是“onBlur”吗?

如果你看一下onBlur事件道场API文档,它不传递一个事件对象像你期待

onBlur() 
Defined by: dijit/_FocusMixin 

Called when the widget stops being "active" because focus moved to something outside of it, or the user clicked somewhere outside of it, or the widget was hidden. 
Examples 
Example 1 
var btn = new Button(); 
// when /my/topic is published, this button changes its label to 
// be the parameter of the topic. 
btn.subscribe("/my/topic", function(v){ 
this.set("label", v); 
}); 

接下来,在你的事件处理程序,您要更改文本以小写,这可以像

makeAllSmall : function(){ 
    var currVal=this.get("value"); 
    currVal = currVal.toLowerCase(); 
    /**Some Other business logic on currVal **/ 
} 

这样做没有事件处理程序的另一种方法是强制ValidationTextBox一切转换为使用施工参数,以小写像

完成210
<input 
      id ="NZ2", 
      data-dojo-attach-point = "NZ2" 
      data-dojo-attach-type = "ecm.widget.ValidationTextBox" 
      data-dojo-props='lowercase:true' 
      data-dojo-attach-event = "onBlurr : makeAllSmall" 
     /> 

请注意,我已经加入data-dojo-props='lowercase:true'

希望这有助于。

+0

感谢。这是我正在寻找的东西。而我的那个额外的r – Shital

0

您应该能够通过向DOM事件附加到您的自定义窗口小部件:在标记

  • 使用数据属性data-dojo-attach-event
  • 并使用_AttachMixin传递你的callBack函数。

实施例:


<div id="somenode"><span data-dojo-attach-point="anattachpoint" 
    data-dojo-attach-event="click: clicked">Click me</span></div> 

var MyDijit = declare([ _WidgetBase, _AttachMixin ], { 
    // .. declaration goes here .. 
    clicked: function(e) { 
     // handle event 
    } 
}); 
// instantiate the dijit instance, which will attach to the 'somenode' div. 
var mydijit = new MyDijit({}, dom.byId('somenode')); 
mydijit.startup(); 
相关问题