I was trying to return an array of data from python function to Javascript. I am using eel python module. The python function returns a string with ease, but when I tried to return an array object, it returns nothing to javascript.
Here is the python function:
@eel.expose
def get_list_data(column_name):
tree = ET.parse('resources.xml')
root = tree.getroot()
column_list_data = []
for child in root.findall('column'):
if child.get('name') == column_name:
for grandchild in child:
column_list_data.append(grandchild.text)
return(column_list_data)
And here is the javascript function.
function getListData(){
let retData = eel.get_list_data("Response")();
console.log(retData);
}
getListData();
Here is the console log shows.
Promise
__proto__: Promise
[[PromiseStatus]]: "resolved"
[[PromiseValue]]: Array(0)
asyncbefore calling in JS or usePromise.resolve(...)ornew Promise()syntax. There are many ways to resolve a promise in JS (stackoverflow.com/questions/26711243/…)async function getListData()won't do the job. You'll have to use await on the asynchroneous promise which then makes your function asynchroneous as well and therefore requires the async declaration:let retData = await eel.get_list_data("Response")();.