Robert Scheitlin, GISP wrote:
Ann,
Ahh, now I see what you were saying about the on event handler. So the issue I see in your code is that _AttributeTable is likely out of scope inside your on event handler. So you need to use lang.htich to get around that.
var _AttributeTable = this.widgetManager.getWidgetsByName("AttributeTable");
html.setAttr(this.domNode, 'title', this.label);
d = domConstruct.create('div');
on(d, 'click', lang.hitch(this, function{
_AttributeTable._switchTable();
}),d);
Or you can use:
this._AttributeTable = this.widgetManager.getWidgetsByName("AttributeTable");
html.setAttr(this.domNode, 'title', this.label);
d = domConstruct.create('div');
on(d, 'click', function{
this._AttributeTable._switchTable();
},d);
Hi Robert:
I added the code to the widget. But on clicking the button, nothing happens. What can be wrong?
My full code of Widget here:
define([
'dojo/_base/declare',
'jimu/BaseWidget',
'dojo/_base/html',
'dojo/on',
'dojo/_base/lang',
'dojo/dom-construct',
'dojo/dom-class',
'dojo/topic'
],
function(
declare,
BaseWidget,
html,
on,
lang,
domConstruct,
domClass,
dojoTopic) {
var clazz = declare([BaseWidget], {
name: 'AttributeTableToggle',
baseClass: 'jimu-widget-AttributeTableToggle',
icon: 'images/icon.png',
startup: function() {
this.inherited(arguments);
var _AttributeTable = this.widgetManager.getWidgetsByName("AttributeTable");
html.setAttr(this.domNode, 'title', this.label);
d = domConstruct.create('div');
on(d, 'click', lang.hitch(this, function(){
domClass.toggle(this, "selected");
dojoTopic.publish('attributeTable/toggle', "selected")
_AttributeTable._switchTable();
}),d);
// html.place(d, this.domNode);
}
});
return clazz;
});