我试图循环访问JSON对象以动态构建连接的下拉菜单(年份,品牌,型号,车型)。在FF和Chrome中,它运行良好。在IE11中,它没有。它看起来甚至不像是同一个物体。
此过程的工作方式如下:执行Ajax调用以获取模型年份列表,选定年份的列表,所选品牌的模型以及所选模型的车辆类型。将其作为JSON字符串返回(包括其他数据位),找到符合条件的车辆数量。这一切都有效。
然后,遍历年份,制作,制作和输入列表以填充下拉列表。这就是它倒塌的地方。
data = arrTemp[1].evalJSON(); // arrTemp[1] contains the return string
// arrControls is an associative array listing the dropdowns
// and their default values, labels, etc.
for(var ckey in arrControls){
if(arrControls.hasOwnProperty(ckey)){
// cKey is the id of the control, and also the key
// for that element of the array. Off of that are
// properties like "fieldname", "caption"
// e.g.
// tmpControls['yearFrom'] = [];
// tmpControls['yearFrom']['fieldname'] = "@YearFrom";
// tmpControls['yearFrom']['caption'] = "-- Model Year";
// tmpControls['yearFrom']['reselect'] = selYear;
curControl = arrControls[ckey];
fieldname = curControl['fieldname'];
caption = curControl['caption'];
// "data" is the JSON object
currentPiece = data[fieldname]; // get the data for this particular object
/*
// this bit is all just fine in all browsers
console.log("ckey: " + ckey);
console.log("caption: " + caption);
console.log("currentPiece: " + currentPiece);
// shows up in FF as [object object][object object]...etc etc etc
*/
C = $(ckey) // get the control we plan to populate
// the next line works in all browsers, so I know I'm correctly referencign the controls.
C.style.border = "1px solid red";
C.options.length = 0;
opt = document.createElement("option");
opt.text = caption;
opt.value = "";
C.options.add(opt);
// we're good up to here. All this works as it should.
for(var vKey in p){
if (p.hasOwnProperty(vKey)) {
item = p[vKey];
// "inspect" is a function I got from a StackOverflow answer
// it iterates the object and tell you properties, functions, etc. of the object
// it doesn't look even close to the same between IE11 and FF
console.log(inspect(item));
opt = document.createElement("option");
opt.text = item['displayValue'];
opt.value = item['fieldValue'];
C.options.add(opt);
}
}
C.value = curControl['reselect'];
}
}
在InternetExplorer 11中,inspect看起来像这样:
(function) argumentNames
(function) bindAsEventListener
(function) curry
(function) delay
(function) defer
(function) wrap
(function) methodize
在FF / Firebug中,它看起来像这样:
(string) fieldValue
(string) displayValue
我想我可以重写整个混乱并使用简单的数组,但我宁愿使用JSON对象来保持一致性(就像我为这个办公室所做的其他项目一样。)
我已经在这个问题上殴打了三个小时,而且我在我的智慧中挣扎着。结束。 " fieldValue方法"和" displayvalue"是我想要的,但IE和FF之间的对象解析存在一些差异,我无法弄清楚。