我在 AJAX 调用中通过服务器发送一个列表(在 python 中)作为响应。
回应是[u"<select id = '1_level1'><option>Select Region </option><option>Asia / Pacific</option><option>North America</option></select>", u"<select id = '2_level1'><option>Select Region </option><option>Asia / Pacific</option><option>North America</option></select>"]
当我使用
success: function(result){
$("#compare1").html(result.split(",")[0]);
它打印两个选择选项。如何拆分列表?
已编辑
elif request.POST.has_key('compare_options'):
#user_organization_id =
compare_id = request.POST.getlist('id[]')
level1_options = Level1Detail.objects.filter(organization_id = 1) # change it with user_organization_id
option = []
for ids in compare_id:
option_str = ""
level1_options_str = "<option>Select Region </option>"
for options in level1_options:
level1_options_str += "<option>"+options.level1_name+"</option>"
option_str = "<select id = '"+ids+"level1'>" + level1_options_str + "</select>"
option.append(option_str)
print option
return HttpResponse(option)