我有一个website并带有联系表。
该表单有一个名为POS Company Name
“的字段。我需要在该字段中填充需要从.json
文件中提取的项目。
[
{
"name": "POSitouch",
"supportedVersions": [
"5.36+",
"6.36+",
"QuickMenu 2.6.7.12+"
]
},
{
"name": "Aloha",
"supportedVersions": [
"5.1+"
]
},
{
"name": "Posera Maitre'D",
"supportedVersions": [
"7.0"
]
},
{
"name": "Veloce",
"supportedVersions": [
"6.x",
"7.x",
"8.x",
"9.x"
]
},
{
"name": "Azbar AZPos",
"supportedVersions": [
"6.x",
"7.x",
"8.x"
]
},
{
"name": "Dinerware",
"supportedVersions": [
"3.x"
]
},
{
"name": "Micros 3700",
"supportedVersions": [
"RES4",
"RES5"
]
},
{
"name": "Micros Simphony",
"supportedVersions": [
"1.6+"
]
},
{
"name": "Micros First Edition",
"supportedVersions": [
"1.6+"
]
},
{
"name": "EPOS Now",
"supportedVersions": [
"All Versions"
]
},
{
"name": "Maxirest",
"supportedVersions": [
"4.9+"
]
},
{
"name": "Silverware",
"supportedVersions": [
"Avrio",
"Legacy"
]
},
{
"name": "OKPOS",
"supportedVersions": [
"All Versions"
]
},
{
"name": "Tiller",
"supportedVersions": [
"All Versions"
]
},
{
"name": "Tango",
"supportedVersions": [
"All Versions"
]
},
{
"name": "Zonal",
"supportedVersions": [
"Aztec 3.6+"
]
},
{
"name": "Lavu",
"supportedVersions": [
"All Versions"
]
},
{
"name": "Bepoz/Vectron",
"supportedVersions": [
"4.3+"
]
},
{
"name": "EasyPos",
"supportedVersions": [
"All Versions"
]
},
{
"name": "IdealPos",
"supportedVersions": [
"7.x+"
]
},
{
"name": "H&L",
"supportedVersions": [
"8+"
]
}
]
用户单击此字段时,它需要显示.json file.
中显示的项目列表。网站可以提取此数据并将其存储在本地文件或数据库中,或在每次请求时调用它。
答案 0 :(得分:-1)
您可以使用带有for循环的函数插入wordpress html中。
window.onload = function load (){
console.log ('readyu');
var json = [
{
"name": "POSitouch",
"supportedVersions": [
"5.36+",
"6.36+",
"QuickMenu 2.6.7.12+"
]
},
{
"name": "Aloha",
"supportedVersions": [
"5.1+"
]
},
{
"name": "Posera Maitre'D",
"supportedVersions": [
"7.0"
]
},
{
"name": "Veloce",
"supportedVersions": [
"6.x",
"7.x",
"8.x",
"9.x"
]
},
{
"name": "Azbar AZPos",
"supportedVersions": [
"6.x",
"7.x",
"8.x"
]
},
{
"name": "Dinerware",
"supportedVersions": [
"3.x"
]
},
{
"name": "Micros 3700",
"supportedVersions": [
"RES4",
"RES5"
]
},
{
"name": "Micros Simphony",
"supportedVersions": [
"1.6+"
]
},
{
"name": "Micros First Edition",
"supportedVersions": [
"1.6+"
]
},
{
"name": "EPOS Now",
"supportedVersions": [
"All Versions"
]
},
{
"name": "Maxirest",
"supportedVersions": [
"4.9+"
]
},
{
"name": "Silverware",
"supportedVersions": [
"Avrio",
"Legacy"
]
},
{
"name": "OKPOS",
"supportedVersions": [
"All Versions"
]
},
{
"name": "Tiller",
"supportedVersions": [
"All Versions"
]
},
{
"name": "Tango",
"supportedVersions": [
"All Versions"
]
},
{
"name": "Zonal",
"supportedVersions": [
"Aztec 3.6+"
]
},
{
"name": "Lavu",
"supportedVersions": [
"All Versions"
]
},
{
"name": "Bepoz/Vectron",
"supportedVersions": [
"4.3+"
]
},
{
"name": "EasyPos",
"supportedVersions": [
"All Versions"
]
},
{
"name": "IdealPos",
"supportedVersions": [
"7.x+"
]
},
{
"name": "H&L",
"supportedVersions": [
"8+"
]
}
];
function read (){
for (var i=0; i<json.length; i++){
// console.log('name: ', json[i].name); //to write it in the console
// console.log('version: ', json[i].supportedVersions[0]); //to write it in the console
document.write(' name: ', json[i].name, "<BR>"); //to write it in html
document.write(' version: ', json[i].supportedVersions[0], "<BR><BR>"); //to write it in html
}
}
read();
}