2011-11-03 81 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