jqGrid动态选择

jqGrid dynamic select

本文关键字:选择 动态 jqGrid      更新时间:2023-09-26

我从2009年就开始关注这个链接了

返回的json对象(这是一个有效对象)是…

{"Refs":{"str":"1:Airport;3:Customer Location;4:Hotel;2:Regional Office;"}}

在我的js中,我会做…

var getRefIdUrl="http://blah?_service=appdev94&_program=tastest.jsonRefPoints.sas&action=getRefId";
var refs = $.ajax({url: getRefIdUrl, async: false, success: function(data, result) {if (!result) alert('Failure to retrieve the Reference Types.');}}).responseText;

在colmodel中我正在做…

  {name:'typeID', index: 'typeID', width: 80, sortable: true, editable: true, edittype: 'select',  formatter:'select' ,editrules: { required: true } , editoptions:{value:refs}},

将值返回到变量refs中。在网格视图模式下,它看起来很棒,并将底层值与正确的文本显示相匹配。辉煌。

当我点击EditGridRow下拉菜单看起来准确,但当我检查元素时,它看起来像这样…

<option role="option" value="{Content""> {"str": 1:Airport</option>
<option role="option" value="3">Customer Location</option>
<option role="option" value="4">Hotel</option>
<option role="option" value="2">Regional Office</option>
<option role="option" value=""}}">undefined</option>

注意第一个和最后一个是如何时髦的…这将导致我相信返回的json对象不是正确的格式。

但在我花太多时间探索这个问题之前,我想知道2014年你会怎么做。这种联系可以追溯到2009年。每一个现有的行将有一个有效值在我的数据,但如果我想添加一个新的记录,那么我想我更喜欢它有它说"选择一个值"或下拉列表中的东西,而不是未定义。

我很感激你的帮助。谢谢…

如果您的JSON对象是:

{"Content":{"str":"1:Airport;3:Customer Location;4:Hotel;2:Regional Office;"}}

然后使用:

 editoptions:{value:refs.Content.str}}