2017-10-08 72 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(); 
相關問題