PDA

View Full Version : how to add listeners for html dom in controller?



janksen
25 Dec 2011, 12:07 AM
When i tried to add listeners for html dom,but it doesn't work.
this is my code:

view:

.....//some code
items:
[
{
docked: 'right',
width: 104,
id: 'test',
html: ['<div class="grid_item grid_item_7 sidebtn" id="login_btn_exit">退出</div>',
'<div class="grid_item grid_item_7 sidebtn" id="login_btn_delete" >删除</div>'].join('')
}
]
....//some code

//my controller code

....//some code

init: function() {
this.control({
'div[id="login_btn_delete"]':
{
tap: this.onBtnExitTap
},
'#login_btn_delete':
{
tap: this.onBtnDeleteTap
}
},

onBtnExitTap:function()
{
alert('exit');//it doesn't work
},

onBtnDeleteTap:function()
{
alert('delete'); // it doesn't work
},

sorry for my pool English,any body can understand my problem and give me some help?

mitchellsimoens
25 Dec 2011, 5:59 AM
this.control can only listen to components as the string selector is a ComponentQuery selector.

In order to do this, you have to add a listener to the element after it has been created.

linuxyf
25 Dec 2011, 5:26 PM
var ojfile = document.getElementById('readjsonfile');
ojfile.addEventListener("change", this.onReadJsonContent, false);