难以阅读 w3.js 中的信息

Difficulty reading information in w3.js

在w3.js

    {
"customers":[
{"CustomerName" : "Alfreds Futterkiste","City" : "Berlin","Country" : "Germany"},
{"CustomerName" : "Berglunds snabbköp","City" : "Luleå","Country" : "Sweden"},
]}


<select id="id01">
  <option w3-repeat="customers">{{CustomerName}}</option>
</select>



<script>
w3.getHttpObject("customers.js", myFunction);

function myFunction(myObject) {
  w3.displayObject("id01", myObject);
}
</script>

但我的对象不是任何名称(客户),而是:

[{"id":12,"name":"hamwrew"},{"id":13,"name":"mamad2"}]

如何显示我的对象?在 html 或 jsp 页中

你没有一个对象,而是一个数组,所以首先从你的数组创建一个对象:

var dataArray = [{"id":12,"name":"hamwrew"},{"id":13,"name":"mamad2"}];
var nameList = { names: dataArray };

所以:

    <select id="id01">   
      <option w3-repeat="names" value={{id}}>{{name}}</option>
    </select>

    <script>
      w3.getHttpObject("customers.js", myFunction);

      function myFunction(myArray) {   
        var nameList = { names: myArray};   
        w3.displayObject("id01", nameList);
      }
   </script>