03-15-2020 12:52 PM
How can I access the data returned by serviceXhr? I want to access the series array in the function that called getSeries function. But It seems the data is retrieved in the successCallback and I can't get the data outside of it?
getSeries:function archive_list__getSeries(archiveList) {
this.serviceXhr({
url: AlfConstants.PROXY_URI + "/rl/archive/archive-list-series?archiveList=" + archiveList,
method: "GET",
successCallback: function (response) {
var series = [];
if (response && response.result)
{
var seriesData = response.result;
seriesData.sort(this.naturalSort);
for (var i=0; i<seriesData.length; i++)
{
var row = {
name: "alfresco/lists/views/layouts/Row",
config: {
widgets: [
{
name: "alfresco/lists/views/layouts/Cell",
config: {
widgets: [
{
name: "alfresco/html/Label",
config: {
label: seriesData[i].title + " (" + seriesData[i].id + ")"
}
}
]
}
},
this.getSeriesAddAction(seriesData[i].nodeRef)
]
}
};
series.push(row);
}
}
},
callbackScope: this
});
},
04-07-2020 07:50 AM
Hi, You can access below way.
_MyarrayData: null, constructor: function abc__constructor(args) { this.alfSubscribe(this.setData, lang.hitch(this, this.onSetData)); }, getSeries:function archive_list__getSeries(archiveList) { this.serviceXhr({ url: AlfConstants.PROXY_URI + "/rl/archive/archive-list-series?archiveList=" + archiveList, method: "GET", successCallback: function (response) { var series = []; if (response && response.result) { } }, callbackScope: this }); this.alfPublish(this.setData, { myData: pass_data_here }); }, onSetData: function bbbbb(publishPayload) { if (publishPayload && publishPayload.myData) { this._MyarrayData = publishPayload.myData; } }
Here _MyarrayData is variable.
Publish topic from getSeries which is subscribe in constructor and it will call onSetData which is assigning your data to that variable.After that you can access that variable like this._MyarrayDatat.
Explore our Alfresco products with the links below. Use labels to filter content by product module.