How to subscribe to more than one attribute in a widget

4
For a custom widget I'm trying to subscribe to two attributes from the context object, one wich only triggers the updateRendering and one which instructs the widget to reload the data. Ive tried several options but none work.   Option 1: two subscribes Update: I have no clue why, but this one does work now. Probably some hidden typo in it the first time, no idea why it didn't generate and error though. var attrHandle = this.subscribe({ guid: this._contextObj.getGuid(), attr: this._association, callback: dojoLang.hitch(this, function(guid, attr, attrValue) { this._updateRendering(); }) }); var reloadDataHandle = this.subscribe({ guid: this._contextObj.getGuid(), attr: this.reloadDataAttribute, callback: dojolang.hitch(this, function(guid, attr, attrValue) { this._reloadData(); }) }); var validationHandle = this.subscribe({ guid: this._contextObj.getGuid(), val: true, callback: dojoLang.hitch(this, this._handleValidation) }); this._handles = [attrHandle, reloadDataHandle, validationHandle]; No errors, but the script simply runs forever as soon as the second attribute subscription is reached. So the page is never loaded.   Option 2: see if the attribute subscription accepts an array var attrHandle = this.subscribe({ guid: this._contextObj.getGuid(), attr: [this._association, this.reloadDataAttribute], callback: dojoLang.hitch(this, function(guid, attr, attrValue) { this._updateRendering(); }) }); var validationHandle = this.subscribe({ guid: this._contextObj.getGuid(), val: true, callback: dojoLang.hitch(this, this._handleValidation) }); this._handles = [attrHandle, validationHandle]; This seems to work fine, the page loads, again no errors. However the attrHandle is never trigerred when any of the attributes change.   Option 3: add an object handle, figure out later how to check what attributes where changed var objHandle = this.subscribe({ guid: this._contextObj.getGuid(), callback: dojoLang.hitch(this, function(guid) { this._updateRendering(); }) }); var validationHandle = this.subscribe({ guid: this._contextObj.getGuid(), val: true, callback: dojoLang.hitch(this, this._handleValidation) }); this._handles = [attrHandle, validationHandle]; However this comes with the problem that the object handle isn't called when any attribute changes (even though the console shows "mendix.sys.Data.update"), it's only called when I add an OnChange to the other input and refresh the entire object in the OnChange.     This is all in Mendix 6.10.2, does anyone have a solution for this?
asked
2 answers
1

I've checked your code, option 1 should work (also checked this against the source code for this.subscribe). I see your edit, you have probably made a typo indeed.

As for the handles, you don't have to create your own handles property anymore:

You could do this.unsubscribeAll() and just use this.subscribe.

See the example in the AppStoreWidgetBoilerplate

answered
0

Strange, the first method worked for me in 5.9.1. What happenes if you use 2 attributes, and no assocation, just for a test?

answered