dojo - Adding a custom widget on call back method -


i have call method called other class when event occurs, send objects parameters

    loadingisdone : function(evt)     {         console.log(evt);         for(var i=0; i<evt.layers.length;i++)         {            var row = new _layerrow(evt.layers[i].layer);             domconstruct.place(row.domnode,this.containerdiv,"last");         }     } 

for each object received need create custom widget called _layerrow, having 1 checkbox , label

when debug code pointer not coming 2nd line of loop.

and no error in console..

but when call same in different file below testing purpose

               var obj = new object();                 obj.id = "124";                 obj.name = "chiru";                 var lay = new _layerrow(obj);                 domconstruct.place(lay.domnode,win.body(),1); 

the _layerrow widget working fine

_layerrow.js

define([ "dojo/_base/declare", "dijit/_widgetbase", "dijit/_ondijitclickmixin", "dijit/_templatedmixin", "dojo/text!../templates/_layerrow.html" ], function (declare, _widgetbase, _ondijitclickmixin,_templatedmixin, template) {  return declare([_widgetbase,_ondijitclickmixin, _templatedmixin], {     templatestring: template,      layer : null,      constructor : function( layerobj)     {         this.id = layerobj.id;         this.layer = layerobj;      },     postcreate : function()     {         this.inherited(arguments);         this.layername.innerhtml = this.layer.name;     }  });  }); 

and templates/_layerrow.html

<div>   <input type="checkbox" id="${id}">   <label for="${id}" data-dojo-attach-point="layername"></label> </div> 

any idea why not working.. how can find issue in this

most common reason callbacks fail incorrect scope.

because in asynchronous callbacks such above, context code executing in has changed. no longer refer object provided it, context refer enclosing object, callback. around this, can use hitch() force function retain original context

i see reference this in callback, use hitch correct scope.

more info: http://dojotoolkit.org/reference-guide/1.9/dojo/_base/lang.html#hitch


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -