I'm fiddling with luci-app-example to add some more examples of how to work with LuCI and Javascript.
I have two functions that take data and build forms/tables from the data. One uses E() and the other uses JSONMap. The render()
function looks like:
render_sample2_using_jsonmap: function (sample) {
...
var m = new form.JSONMap(sample, _('JSONMap'), _('Description'));
...
return m;
},
render: function (data) {
var sample1 = data[0] || {};
var sample2 = data[1] || {};
return E('div', { 'class': 'cbi-map', 'id': 'map' }, [
E('div', { 'class': 'cbi-section' }, [
E('div', { 'class': 'left' }, [
E('h3', _('Sample 1 using JS array to make a table')),
this.render_sample1_using_array(sample1)
]),
E('div', { 'class': 'left' }, [
E('h3', _('Sample 2 using JSONMap to make a form')),
this.render_sample2_using_jsonmap(sample2).render()
]),
]),
]);
},
render_sample2_using_jsonmap()
returns m
; m is defined as new form.JSONMap()
.
The rendered view shows the table built for sample1 correctly, and the header for sample2. However, sample2's render() call is returning [object Promise]
.
Is it possible to force the form's render() method to actually execute, instead of of returning the promise?
I know I can do an inverse here, and embed E()
generated DOM nodes inside a form's content (luci-app-wireguard does this), but that feels like a dirty hack for a case where I want to show some data using E()
, and also have a viable form that can update a configuration.