<div class="iteye-blog-content-contain" style="font-size: 14px;">
<p>1、创建Editor</p>
<p> </p>
<pre name="code" class="java">{
field: 'categoryname' ,width:100,title:'所属类别' ,editor:{type: 'combobox',options:{
valueField: 'id',
textField: 'text',
panelHeight: 'auto'
}}
}
</pre>
<p> 设置<span style="font-family: monospace; font-size: 1em; line-height: 1.5;">panelHeight: 'auto' 使其不会出现一大片空白!</span></p>
<p> </p>
<p> </p>
<p><span style="font-family: monospace; font-size: 1em; line-height: 1.5;">2、在双击编辑该行是调用ajax 请求后台返回参数</span></p>
<p> </p>
<pre name="code" class="java">onDblClickRow : function(rowIndex,rowData){
if (editRow != undefined) {
$("#admin_gamelist_datagrid").datagrid('endEdit', editRow);
}
if (editRow == undefined) {
$("#admin_gamelist_datagrid").datagrid('beginEdit', rowIndex);
editRow = rowIndex;
$("#admin_gamelist_datagrid").datagrid('unselectAll');
}
synchCategory(rowIndex,rowData);
},</pre>
<p> <span style="font-family: monospace; font-size: 1em; line-height: 1.5;">synchCategory(rowIndex,rowData); 该方法为请求方法。</span></p>
<p> </p>
<p> </p>
<p><span style="font-family: monospace; font-size: 1em; line-height: 1.5;">3、将返回的值加载进combobox</span></p>
<p> </p>
<pre name="code" class="js">function synchCategory(rowIndex,rowData){
var jqData;
var url = '${pageContext.request.contextPath}/skipController/secCate.do?pid=' +rowData.pcategoryid;
var ed = $('#admin_gamelist_datagrid' ).datagrid( 'getEditor',{index:rowIndex,field: 'categoryname' });
$.ajax({
url:url,
dataType : 'json',
type : 'POST',
success: function (data){
jqData = data;
$(ed.target).combobox( 'loadData' , jqData);
}
});
}
</pre>
<p> </p>
<p> </p>
<p><span style="font-family: monospace; font-size: 1em; line-height: 1.5;">4、后台处理逻辑</span></p>
<p> </p>
<pre name="code" class="java">@RequestMapping ("/secCate" )
@ResponseBody
public List&lt;Pcategory&gt; cateSecList(String pid){
List&lt;Pcategory&gt; CateSecList = categoryService .getCateSecList(pid);
return CateSecList;
}
</pre>
<p> </p>
<p> </p>
<p><span style="font-family: monospace; font-size: 1em; line-height: 1.5;">5、效果如图所示:</span></p>
<p><span style="font-family: monospace; font-size: 1em; line-height: 1.5;"><br><img src="http://dl2.iteye.com/upload/attachment/0089/1960/2dcce1d1-05e0-31d1-a63a-6e8ff261cec7.png" alt=""></span></p>
<p><span style="font-family: monospace; font-size: 1em; line-height: 1.5;">效果一<br><br><img src="http://dl2.iteye.com/upload/attachment/0089/1962/3f367a3d-01a9-3ce3-9656-9b7664049a23.png" alt=""><br> <br> 效果二<br> </span></p>
<p> </p>
<p> </p>
</div>