我正在尝试使用预制库来配置SIP电话。他们似乎已经使用JSON作为模板,而我在不熟悉的领域。有许多品牌/型号,有些还有多个模板。我希望能够获取模板的内容并将其转换为PHP表单。我不确定如何编写不同的部分名称。我想编写一个PHP函数来完成所有操作,无论使用何种模板文件。 以下是我正在使用的两个模板:
{
"template_data":{
"category":[
{
"name":"keys",
"subcategory":[
{
"name":"Soft Keys (9480i\/6755i\/6757i)",
"item":[
{
"description":"Soft Keys (9480i\/6755i\/6757i)",
"type":"loop",
"loop_start":"1",
"loop_end":"18",
"data":{
"item":[
{
"variable":"$softkey_type",
"default_value":"empty",
"category":"keys",
"description":"Soft Key {$count} Type",
"type":"list",
"data":[
{
"text":"Empty",
"value":"empty"
},
{
"text":"Services",
"value":"services"
},
{
"text":"Speed Dial",
"value":"speeddial"
},
{
"text":"Line",
"value":"line"
},
{
"text":"BLF",
"value":"blf"
},
{
"text":"List",
"value":"list"
},
{
"text":"Do Not Disturb",
"value":"dnd"
},
{
"text":"XML URL",
"value":"xml"
},
{
"text":"BLF Transfer",
"value":"blfxfer"
},
{
"text":"Intercom",
"value":"icom"
},
{
"text":"Pickup",
"value":"pickup"
},
{
"text":"Flash",
"value":"flash"
},
{
"text":"Special Prefix Code",
"value":"spre"
},
{
"text":"Park",
"value":"park"
},
{
"text":"Directory",
"value":"directory"
},
{
"text":"Callers",
"value":"callers"
}
]
},
{
"variable":"$softkey_label",
"default_value":"",
"description":"Soft Key {$count} Label",
"type":"input"
},
{
"variable":"$softkey_value",
"default_value":"",
"description":"Soft Key {$count} Value",
"type":"input"
},
{
"variable":"$softkey_states",
"default_value":"Any",
"description":"Soft Key {$count} States",
"type":"list",
"data":[
{
"text":"Any",
"value":"connected,idle,incoming,outgoing"
},
{
"text":"Connected",
"value":"connected"
},
{
"text":"Idle",
"value":"idle"
},
{
"text":"Incoming",
"value":"incoming"
},
{
"text":"Outgoing",
"value":"outgoing"
},
{
"text":"Idle or Incoming",
"value":"idle,incoming"
},
{
"text":"Connected or Outgoing",
"value":"connected,outgoing"
},
{
"text":"None (Hide Button)",
"value":[
]
}
]
},
{
"type":"break"
}
]
}
}
]
}
]
}
]
}
}
这是另一个:
{
"template_data":{
"category":[
{
"name":"keys",
"subcategory":[
{
"name":"Multi Function Keys",
"item":[
{
"variable":"$key_mode_01",
"default_value":"",
"description":"Key 1 Mode",
"type":"list",
"data":[
{
"text":"Speed Dial",
"value":"0"
},
{
"text":"BLF",
"value":"1"
},
{
"text":"Presence Watcher",
"value":"2"
},
{
"text":"Eventlist BLF",
"value":"3"
}
]
},
{
"variable":"$key_name_01",
"default_value":"Speed Dial 1",
"description":"Key Name",
"type":"input"
},
{
"variable":"$speed_dial_01",
"default_value":"*01",
"description":"Value #1",
"type":"input"
},
{
"type":"break"
},
{
"variable":"$key_mode_02",
"default_value":"",
"description":"Key 2 Mode",
"type":"list",
"data":[
{
"text":"Speed Dial",
"value":"0"
},
{
"text":"BLF",
"value":"1"
},
{
"text":"Presence Watcher",
"value":"2"
},
{
"text":"Eventlist BLF",
"value":"3"
}
]
},
{
"variable":"$key_name_02",
"default_value":"Speed Dial 2",
"description":"Key Name",
"type":"input"
},
{
"variable":"$speed_dial_02",
"default_value":"*02",
"description":"Value #2",
"type":"input"
},
{
"type":"break"
},
{
"variable":"$key_mode_03",
"default_value":"",
"description":"Key 3 Mode",
"type":"list",
"data":[
{
"text":"Speed Dial",
"value":"0"
},
{
"text":"BLF",
"value":"1"
},
{
"text":"Presence Watcher",
"value":"2"
},
{
"text":"Eventlist BLF",
"value":"3"
}
]
},
{
"variable":"$key_name_03",
"default_value":"Speed Dial 3",
"description":"Key Name",
"type":"input"
},
{
"variable":"$speed_dial_03",
"default_value":"*03",
"description":"Value #3",
"type":"input"
},
{
"type":"break"
},
{
"variable":"$key_mode_04",
"default_value":"",
"description":"Key 4 Mode",
"type":"list",
"data":[
{
"text":"Speed Dial",
"value":"0"
},
{
"text":"BLF",
"value":"1"
},
{
"text":"Presence Watcher",
"value":"2"
},
{
"text":"Eventlist BLF",
"value":"3"
}
]
},
{
"variable":"$key_name_04",
"default_value":"Speed Dial 4",
"description":"Key Name",
"type":"input"
},
{
"variable":"$speed_dial_04",
"default_value":"*04",
"description":"Value #4",
"type":"input"
},
{
"type":"break"
},
{
"variable":"$key_mode_05",
"default_value":"",
"description":"Key 5 Mode",
"type":"list",
"data":[
{
"text":"Speed Dial",
"value":"0"
},
{
"text":"BLF",
"value":"1"
},
{
"text":"Presence Watcher",
"value":"2"
},
{
"text":"Eventlist BLF",
"value":"3"
}
]
},
{
"variable":"$key_name_05",
"default_value":"Speed Dial 5",
"description":"Key Name",
"type":"input"
},
{
"variable":"$speed_dial_05",
"default_value":"*05",
"description":"Value #5",
"type":"input"
},
{
"type":"break"
},
{
"variable":"$key_mode_06",
"default_value":"",
"description":"Key 6 Mode",
"type":"list",
"data":[
{
"text":"Speed Dial",
"value":"0"
},
{
"text":"BLF",
"value":"1"
},
{
"text":"Presence Watcher",
"value":"2"
},
{
"text":"Eventlist BLF",
"value":"3"
}
]
},
{
"variable":"$key_name_06",
"default_value":"Speed Dial 6",
"description":"Key Name",
"type":"input"
},
{
"variable":"$speed_dial_06",
"default_value":"*06",
"description":"Value #6",
"type":"input"
},
{
"type":"break"
},
{
"variable":"$key_mode_07",
"default_value":"",
"description":"Key 7 Mode",
"type":"list",
"data":[
{
"text":"Speed Dial",
"value":"0"
},
{
"text":"BLF",
"value":"1"
},
{
"text":"Presence Watcher",
"value":"2"
},
{
"text":"Eventlist BLF",
"value":"3"
}
]
},
{
"variable":"$key_name_07",
"default_value":"Speed Dial 7",
"description":"Key Name",
"type":"input"
},
{
"variable":"$speed_dial_07",
"default_value":"*07",
"description":"Value #7",
"type":"input"
}
]
}
]
}
]
}
}
看起来这样做的目的正是我想要的,我只是不知道如何开始。我能够从模板文件中检索数据,但从那里丢失了。我曾尝试使用json_decode,但输出似乎没有任何更友好的工作。我也尝试使用php获取模板的内容,然后使用javascript来解析它。这有点工作,但每个文件需要更多的静态变量,如果文件的提供者改变某些东西,可能需要更多的时间编辑。如果有人知道最简单的方法,那将非常感激。
答案 0 :(得分:0)
我会使用handlebars.js来显示信息。看这里:
http://handlebarsjs.com/
我每天都使用它,它很简单:
<tr>
<td>{{clock_number}}</td>
<td style="width: 150px;">{{employee_name}}</td>
<td>{{hourly_wage}}</td>
<td><a href='employee.php?clock_number={{clock_number}}'>Edit</a></td>
</tr>
非常好的自由课程可以帮助你开始:
https://tutsplus.com/course/30-days-to-learn-jquery/