我有一个关于在jqGrid中使用下拉列表的问题。在我的环境中,我使用的是jqGrid 4.4.4 - jQuery Grid(版本4.4.4)和MVC 5。
在下面的代码中,我从控制器动态创建ColNames
和ColModel
。一切正常,除了我希望显示下拉列表值的列。现在,下拉列表为空。为什么它是空的?
此外,价值如何,例如{value:{'FE':'FedEx';'IN':'InTime';'TN':'TNT';'AR':'ARAMEX'}}
,从控制器中的方法动态加载?
model.CreateMeeting = false;
SecondOpinionFacade = new SecondOpinionFacade();
var meeting = SecondOpinionFacade.GetMeeting(id);
model.MeetingDay = meeting.StartDate.Date;
model.MeetingdID = meeting.SecondOpinionMeetingId;
model.FromTime = meeting.StartDate.ToString("HH:mm");
model.ToTime = meeting.EndDate.ToString("HH:mm");
model.NrofGroups = meeting.SecondOpinionGroup.Count;
var list = new[] { new { name = "SecondOpionUserId", index = "SecondOpionUserId", sorttype = "string", sortable=false, hidden = true, editable = true, edittype = "", editoptions= "", formatter = ""} }.ToList();
这里我试图将数据放入下拉列表中,但它似乎不起作用,因为下拉列表显示为空。
list.Add(new { name = "Deltagare", index = "Deltagare", sorttype = "string", sortable = true, hidden = false, editable = true, edittype = "select", editoptions = "{value:{'FE':'FedEx';'IN':'InTime';'TN':'TNT';'AR':'ARAMEX'}}", formatter = "select" });
int counter = 1;
meeting.SecondOpinionGroup.OrderBy(x=> x.SecondOpinionGroupId).ForEach(x =>
{
list.Add(new {name = x.SecondOpinionGroupId.ToString(), index = "Grupp" + counter, sorttype = "string", sortable = false, hidden = false, editable = true, edittype = "checkbox", editoptions = "{ value: 'True:False' }", formatter = "checkbox" });
counter++;
});
var list2 = new[] { "SecondOpionUserId" }.ToList();
list2.Add("Deltagare");
for (int i = 1; i <=model.NrofGroups; i++)
{
list2.Add("Grupp"+i);
}
model.ColNames = JsonConvert.SerializeObject(list2);
model.ColModel = JsonConvert.SerializeObject(list);
return View(model);
答案 0 :(得分:1)
您使用字符串作为editoption
的值。这是错的。 editoptions
的值应为对象。尝试替换
editoptions = "{ value: 'True:False' }"
和
editoptions = "{value:{'FE':'FedEx';'IN':'InTime';'TN':'TNT';'AR':'ARAMEX'}}"
到
editoptions = new { value = "True:False" }
和
editoptions = new { value = "FE:FedEx;IN:InTime;TN:TNT;AR:ARAMEX" }