我有一个ExtJS应用程序。在我的网格中,我使用column renderer函数返回select元素下拉列表。我目前的实施如下:
// grid col renderer fn
renderer:function(val, meta, rec) {
return [
'<select id="states" value="" disabled selected>Select...</option>'+
'<option value="CA">California</option>'+
'<option value="NY">New York</option>'+
'<option value="TX">Texas</option>'+
'<option value="FL">Florida</option>'+
'<option value="NJ">New Jersey</option>'+
'</select>'
];
这一切都运行正常,但现在选项列表将是动态的。示例JSON如下:
"states":[{"value":"CA","name":"California"},{"value":"Ny", "name":"New York"},{...}]
所以我想迭代&#34;状态&#34;数组并为每个对象创建一个选项el,然后将该选项推送到select元素。
由于
答案 0 :(得分:2)
试试这个:
this_select_content = '';
for(var i=0; i < states.length; i++){
var this_select_content += '<option value="' + states[i]['value'] + '">' + states[i]['name'] + '</option>';
}
$("#states").empty().append(this_select_content);
答案 1 :(得分:1)
试试这个:
var this_select_content = '<select id="states">';
for(var i=0; i < states.length; i++){
this_select_content += '<option value="' + states[i]['value'] + '">' + states[i]['name'] + '</option>';
}
this_select_content +='</select>'
$("#states").empty().append(this_select_content);
Basically you need to iterate through the array of states..