JS:
define(["dojo/_base/declare","dojo/dom",
"dijit/_Widget", "dijit/_TemplatedMixin",
"dojo/text!./templates/MainViewWidget.html",
"dijit/layout/TabContainer", "dijit/layout/ContentPane","dijit/layout/BorderContainer","dijit/form/TextBox", "dijit/layout/AccordionContainer"],
function(declare, dom, _Widget, _TemplatedMixin, template){
return declare("package.MainViewWidget", [_Widget, _TemplatedMixin], {
widgetsInTemplate: true,
templateString: template,
constructor: function(){
},
startup: function(){
},
search: function(evt){
alert('hi');
alert(evt);
}
});
});
templates / MainViewWidget.html:
<div class="mainContainer">
<div data-dojo-type="dijit.layout.BorderContainer" data-dojo-props="design:'sidebar', gutters:true, liveSplitters:true" style="width:100%;height:100%;">
<div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'left', splitter:true">
<h2>List of trips</h2>
<br />
<input type="text" data-dojo-type="dijit.form.TextBox" data-dojo-props="placeHolder:'Search...'" data-dojo-attach-event="onchange:'search'"/>
<br />
</div>
<div data-dojo-type="dijit.layout.TabContainer" data-dojo-attach-point="tabContainerDiv" data-dojo-props="region: 'center', tabPosition: 'top', tabStrip:'true', style:'width:80%;height:100%'">
<div data-dojo-type="dijit.layout.ContentPane" title="Summary" data-dojo-props="selected:'true', title:'About'">Welcome. Navigate through the Left pane.</div>
</div>
</div>
</div>
问题是,我想捕捉TextBox
上的事件。正如你在data-dojo-attach-event="onchange:'search'"
看到的那样,我只想用标记来做这件事。我尝试了很多这方面的变化,我无法让它工作。基本上我想要的是在JS中定义一个函数并将其作为标记中的处理程序附加。请帮忙。
答案 0 :(得分:0)
尝试:
data-dojo-attach-event="onChange:search"
Camelcase onChange,搜索周围没有引号。
答案 1 :(得分:0)
遗憾的是,这不受支持。我花了大约两个小时才发现这个。 data-dojo-type
会忽略模板中具有_TemplatedMixin._attachTemplateNodes
属性的任何节点(请参阅line 177)。换句话说,data-dojo-attach-event
只会绑定到纯DOM节点(而不是Dijits)。
这至少适用于v1.8。附加处理在v1.9中有所不同(有一个_AttachMixin
),所以它可能在那里工作。