我正在竭尽全力使我的输出进入AllGroups-Group 1,使其在返回的group_html中的选项值中显示为所选项目。
有人可以帮忙吗?
var existing_groups = $.map(calEvent.users, function(group){
return group.group_id;
});
var group_html = $.map(calEvent.AllGroups, function(group) {
return '<option value="G|' + group.id + '"' + ((existing_groups.indexOf(group.id) > -1) ? ' selected ' : '') + '>' +
'Group: ' + group.name +
'</option>';
}).join('');
return group_html;
// calEvent.users (output)
// 175833: {id: "22322", group_id: "545", name: "Group 1"}
// 175834: {id: "22323", group_id: "534", name: "Group 2"}
//calEvent.AllGroups (output)
//0: {id: "22322", name: "Group 1" }