我终其一生都无法弄清楚如何调用 url,然后将 json 短语化并将其显示在页面上,比如 $w("#Element")。
所以基本上我在 service.jws 的后端做什么
import {fetch} from 'wix-fetch';
// ...
export function getdata(){
fetch('http://tcokchallenge.com/admin_cp/test3.json', {method: 'get'})
.then( (httpResponse) => {
if (httpResponse.ok) {
return httpResponse.json();
} else {
return Promise.reject("Fetch did not succeed");
}
} )
.then(json => console.log(json.glossary["title"]))
.catch(err => console.log(err));
}
在前端,它很草率,但这就是我卡住的地方。
import {getdata} from 'backend/service.jsw';
$w.onReady(function () {
console.log('ready');
$w("#Element").glossary.title.getdata();
})
在 JSON 文件中
{
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ["GML", "XML"]
},
"GlossSee": "markup"
}
}
}
}
}