2011-11-03 47 views

回答

2

你應該通過source一個功能,手動使得AJAX請求,然後對返回的數據進行一些後期處理:

source: function(request, response) { 
    $.ajax({ 
     url: url, 
     data: request, 
     dataType: "json", 
     success: function(data) { 
      var processedData = $.map(data, function(item) { 
       return { 
        value: item._your_property, // Property you want to use for "value" 
        label: item._another_property // Property you want to use for "label" 
       } 
      }); 
      response(processedData); 
     }, 
     error: function() { 
      response([]); 
     } 
    }); 
} 

基本上,使用$.map把你回來的陣列到陣列自動填充小部件支持的對象。

有關工作示例,請查看jQueryUI演示頁面上的JSONP example