Monday 15 September 2014

dojo - domAttr.set(item, 'onclick', 'function(myObject)') doesn't work -



dojo - domAttr.set(item, 'onclick', 'function(myObject)') doesn't work -

i set onclick event item function taking object in arg.

like that:

item = domconstruct.create('li'); domattr.set(item, 'innerhtml', structure.label); domattr.set(item, 'onclick', 'this.myfunction('+structure+')');

problem is:

syntaxerror: missing ] after element list this.myfunction([object object])

i know works instruction :

item = domconstruct.create('li'); domattr.set(item, 'innerhtml', structure.label); domattr.set(item, 'onclick', this.myfunction(structure));

but way executes myfunction without clicking on item.

i want click on item (li) , execute code in myfunction(), function requires argument.

edit :

thanks lot reply tried way. doesn't work too.

no error elem 'li' has no onclick attribute. in html console, see : < li>lien1< /li>

with code :

domattr.set(item, 'onclick', function(){ this.myfunction(structure); });

so when click on label 'lien1', nil happens. because there no onclick attribute. =/

it's same problem on , lang

i think it's little thing alter create work...

thank 1 time again help.

you have utilize dojo on work

item = domconstruct.create('li'); on(item,'click',lang.hitch(this,function(){ this.myfunction(structure); }));

you have utilize on , lang , attach listener on click event

see more details @ link link

another approach this

item = domconstruct.create('li'); childitem = domconstruct.create('a',null,item);

now have both options either on(childitem,'click',lang.hitch(this,function(){ this.myfunction(structure); }));

or this

domattr.set(childitem, 'onclick', 'this.myfunction('+structure+')');

dojo

No comments:

Post a Comment