Let's see what happens
In jqGrid js file
var oSv = options.value; } else if (typeof options.value === 'object') { var oSv = options.value; for ( var key in oSv) { if (oSv.hasOwnProperty(key ) ){ ov = document.createElement("option"); ov.setAttribute("role","option"); ov.value = key; ov.innerHTML = oSv[key]; // this line set option to be selected and the selectedIndex is correct if (!msl && ( $.trim(key) == $.trim(vl) || $.trim(oSv[key]) == $.trim(vl)) ) { ov.selected ="selected"; } if (msl && ($.inArray($.trim(oSv[key]),ovm)>-1 || $.inArray($.trim(key),ovm)>-1)) { ov.selected ="selected"; } elem.appendChild(ov); } } } // before this line the selectedIndex is correct setAttributes(elem, options); // but after this line the selectedIndex is incorrectThe problem must be setAttributes(elem, options);
function setAttributes(elm, atr) { var exclude = ['dataInit','dataEvents','dataUrl', 'buildSelect','sopt', 'searchhidden', 'defaultValue', 'attr']; $.each(atr, function(key, value){ if($.inArray(key, exclude) === -1) { $(elm).attr(key,value); } }); if(!atr.hasOwnProperty('id')) { $(elm).attr('id', $.jgrid.randId()); }Notice this line
$(elm).attr(key,value);The key is "value" and the value is "{RMB:'RMB', USD:'USD', EUR:'EUR', AUD: 'AUD', GBP:'GBP', SGD: 'SGD'}"
Here is the problem. We can add key "value" to exclude array.
Now the functions reads
function setAttributes(elm, atr) { var exclude = ['dataInit','dataEvents','dataUrl', 'buildSelect','sopt', 'searchhidden', 'defaultValue', 'attr']; $.each(atr, function(key, value){ if($.inArray(key, exclude) === -1) { $(elm).attr(key,value); } }); if(!atr.hasOwnProperty('id')) { $(elm).attr('id', $.jgrid.randId()); }It works well now.
没有评论:
发表评论