Load select options dynamically from external serv

2019-09-01 16:39发布

问题:

My problem is to load a select field in touch UI dialog with dynamic options. These options are coming from a external URL via webservices, I am consuming this RESTful services using url defined in one of our global javascript objects like

$.get(mec.serviceConfig.baseUrl + '/movies';

Please understand that the options are coming from third party webservice please do not mention datasource. Whenever I search for loading select options dynamically I get this tutorial

Link to Tutorial This is is not what I want.

In classic UI it is easy with optionsProvider.

In touch UI I am trying to write a script that fetches the data from the external webservice via AJAX ON DIALOG load and set these options in the select field.

Is there any better easier approach ? Can someone please share code snippets?

回答1:

you should create JS listener for your component.

$document.on("dialog-ready", function() {
// there you should find your select field 
//for example
var language = $("[name='./language']").closest(".coral-Select");
//then append to your select field new options from your datasource
});

please see doc: Dynamically updating AEM TouchUI Dialog Select Fields