我有以下数组。
[searchEngineOrder] => Array
(
[0] => keyword
[1] => Google
[2] => Yahoo
[3] => Bing/MSN
)
[Datagrid] => Array
(
[Brand] => Array
(
[1] => Array
(
[keyword] => About Jetwing Hotels Sri Lanka
[Google] => 1
[Yahoo] => 1
[Bing/MSN] => 1
)
[2] => Array
(
[keyword] => Dining at Jetwing Kurulubedda
[Google] => 1
[Yahoo] => 1
[Bing/MSN] => 1
)
) )
这是 php 数组。(我使用json编码)
现在我想创建表。我使用了以下代码。
var headers = data.searchEngineOrder;
var trs = '<tr><td>Brand</td></tr>';
var brands = data.Datagrid.Brand;
for (x in brands) {
trs += '<tr>';
for (y in headers) {
// trs += '<td>'+ brands[x].keyword +'</td>'; This is work
trs += '<td>'+ brands[x].headers[y] +'</td>'; //This is not work
}
trs += '</tr>';
}
$('#keyword-table tbody').html(trs);
如上面的代码 brands[x].keyword
或品牌[x]。谷歌是工作。但是当我使用关键字或谷歌作为变量时,它不起作用。
请帮我。我该怎么做?