2012-06-21 76 views
0
結合

enter image description here jQuery(document).ready(function() { jqGrid的內聯下拉通過AJAX

var grid = $("#list"); 

    var AllCategory={"1":"Computing","2":"Cooking","10":"Fiction","3":"Finance","6":"Language","4":"Medical","11":"News","8":"Philosophy","9":"Religion","7":"Sport","5":"Travel"}; 


    grid.jqGrid({ 
     url: '/SupplierOrder/Select_SupplierOrderDetailByX/', 
     editurl: "clientArray", 
     datatype: 'json', 
     mtype: 'GET', 
     colNames: ['Category', 'Qty'], 
     colModel: [ 
         { 
          name: 'Category', index: 'CategoryID', align: 'left', editable: true, edittype: "select", formatter: 'select', 
          editoptions: { value: AllCategory }, editrules: { required: true } 
         }, 
         { name: 'Qty', index: 'Qty', width: 40, align: 'left', editable: true, edittype: "text", editoptions: { size: "35", maxlength: "50"} } 
       ], 
     pager: jQuery('#pager'), 
     rowNum: 10, 
     rowList: [5, 10, 20, 50], 
     sortname: '', 
     sortorder: '', 
     viewrecords: true, 
     autowidth: true, 
     autoheight: true, 
     imgpath: '/scripts/themes/black-tie/images', 
     caption: 'Supplier Order Detail' 
    }) 
    grid.jqGrid('navGrid', '#pager', { edit: false, add: false, del: true, refresh: false, search: false }, {}, {}, {}, {}); 
    grid.jqGrid('inlineNav', '#pager', { 
     addtext: "Add", 
     edittext: "Edit", 
     savetext: "Save", 
     canceltext: "Cancel" 
    }); 

}); 

這是我的jqGrid。

然後,我首先刪除下面的代碼...

var AllCategory={"1":"Computing","2":"Cooking","10":"Fiction","3":"Finance","6":"Language","4":"Medical","11":"News","8":"Philosophy","9":"Religion","7":"Sport","5":"Travel"}; 

下面的代碼替換,這樣我可以得到動態的數據...

var AllCategory = (function() { 
var list = null; 

$.ajax({ 
async: false, 
global: false, 
type: "POST", 
url: 'Category_Lookup', 
dataType: 'json', 
data: {}, 
success: function (response, textStatus, jqXHR) { 
    list = response; 
}, 
error: function (jqXHR, textStatus, errorThrown) { 
    alert("jqXHR.responseText --> " + jqXHR.responseText + "\njqXHR --> " + jqXHR + "\ntextStatus --> " + textStatus + " \nerrorThrown --> " + errorThrown); 
} 
}); 
alert(list); 

return list; 
})(); 

,我得到下面的消息框.. 。

enter image description here

然後我得到錯誤

enter image description here

任何人都可以請告訴我如何使它正確嗎? 每個建議將不勝感激。

回答

0

格式錯誤。它應該是:

<select><option value=「1」>One</option> <option value=「2」>Two</option></select> 

檢查http://www.trirand.com/jqgridwiki/doku.php?id=wiki:search_config(dataUrl)。

這是一個工作示例。信息取自數據庫,然後在相應的控制器操作中格式化。

<th role="columnheader" class="ui-state-default ui-th-column ui-th-ltr"> 
<div style="width:100%;position:relative;height:100%;padding-right:0.3em;"> 
    <select name="TypeCode" id="gs_TypeCode" style="width: 100%; "> 
    <option></option> 
    <option value="1">cosas!</option> 
    <option value="2">mascosas</option> 
    <option value="3">yast</option> 
    <option value="4">tiparraco</option> 
    </select> 
</div> 
</th> 

很抱歉的蹩腳的格式,但我不能發佈圖片... 希望它能幫助。

+0

感謝您的幫助@smp,'