我正在为一个jqGrid添加一个新字段,它充当表之间的外键,但我使用的选择器只是一堆选项,都是'undefined'。我在我的网站的其他地方使用了以下方法,但我不明白为什么它不在这里工作。这是一个django网站。
视图:
def view_export(request):
#handle what to do if it's a POST request
#set other variables in infoDict
infoDict['tempalte_choices'] = get_template_choices()
return renderutils.render_response("export", infoDict, "export")
def get_template_choices():
choices = []
for template in Template.objects.all():
choices.append((template.id, template.code))
#choices is now a list of tuples (id, display code)
return choices
JS:
templateChoices = "{{template_choices}}";
baseGrid = new BaseGrid("export-grid", {'edit':true});
#set the other jqGrid attributes
baseGrid.colNames = ['Code', 'Name', 'Status', 'Template']
baseGrid.colModel = [
{name:'code', index:'code', width:70 },
{name:'name', index:'name', width:120},
{name:'status', index:'status', width:50},
{name:'template', index:'template', width:100, editable:true, edittype:'select', editoption:{value: templateChoices} }
]