0

我正在尝试使用预制库来配置 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来拆。这是一种工作,但每个文件都需要更多的静态变量,并且如果文件的提供者更改了某些内容,则可能需要更多时间进行编辑。如果有人知道解决此问题的最简单方法,将不胜感激。

4

1 回答 1

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/
于 2013-04-15T17:15:37.407 回答