我可以使用 push({}) 创建我的 javascript 数组,但是我的一个字段有自己的列表。所以我在水平下降时遇到了麻烦。
如下,tradeDetails 数组被定义并且 EXTENSIONS 字段有一个值的集合。我该如何处理下面的这个。
function TradeDetailsToJson(xml) {
var tradeDetails = [];
var tradeId = $(xml).find("tradeHeader tradeId").text();
var tradeDate = $(xml).find("tradeHeader tradeDate").text();
var tradeType = $(xml).find("tradeHeader tradeType").text();
var counterparty = $(xml).find("tradeHeader counterparty").text();
var internalUnit = $(xml).find("tradeHeader internalUnit").text();
var buySell = $(xml).find("tradeHeader buySell").text();
var status = $(xml).find("tradeHeader status").text();
tradeDetails.push({
"tradeId": tradeId,
"tradeDate": tradeDate,
"tradeType": tradeType,
"counterparty": counterparty,
"internalUnit": internalUnit,
"buySell": buySell,
"status": status,
"**extensions**":[]
});
// NOW I'D LIKE TO PUSH MY EXTENSIONS !!
var extName = ""
var extValue = "";
$(xml).find("extensions extension").each(function () {
extName = $(this).find("name").text();
extValue = $(this).find("value").text();
//tradeDetails[extensions].push({ "name": name, "value": value }); ??????
});
}
谢谢你。鲍勃