首页 新闻 会员 周边 捐助

jQueryEasyui combobox加载不了数据,谁能帮我看下!

0
悬赏园豆:20 [已解决问题] 解决于 2012-05-16 09:59

我的目的是使用combobox加载ASHX文件的JSON,但不知道为什么总是加载不到数据。前台代码: <script type="text/javascript" language="javascript" >
        $(function () {
            $("#ddlGys").combobox({
             url: '/Common/Helper.ashx',
             mode:'remote',
             valueFild: 'gys',
             textFild:'gysbh'
            });
        });
    </script>

 <select id="ddlGys"  class="easyui-combobox"  />

后台:

 public List<Supplier> GetSupplier()
        {
            DataTable dt = GingKo.Code.GetDT("select top 20 gysbh,gys from wz_gys");
            List<Supplier> suppliers = new List<Supplier>();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                Supplier tmp = new Supplier();
                tmp.gys = dt.Rows[i]["gys"].ToString();
                tmp.gysbh = Convert.ToInt32(dt.Rows[i]["gysbh"].ToString());
                suppliers.Add(tmp);
            }
            return suppliers;
        }

     //该方法为combobox提供JSON

     public string GetSuppliersJSON()
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            Supplier s = new Supplier();
            List<Supplier> suppliers = s.GetAllSupplier();
            string json = serializer.Serialize(suppliers);
            return json;
        }

问题补充:

 valueFild: 'gysbh',  textFild:'gys'
          

uglydog的主页 uglydog | 初学一级 | 园豆:14
提问于:2012-05-14 10:47
< >
分享
最佳答案
2
var myOptions = {
    val1 : 'text1',
    val2 : 'text2'
};
var mySelect = $('#mySelect');
$.each(myOptions, function(val, text) {
    mySelect.append(
        $('<option></option>').val(val).html(text)
    );
});

http://pastebin.com/6T0b0Grg

第二种方法:

$(document).ready(function() {
  $.ajax({
     type: "POST",
     url: "Default.aspx/GetLanguageList",
     data: '',
     contentType: "application/json; charset=utf-8",
     dataType: "json",
     success: function(msg) {
       $("#ddlLanguage").empty().append($("").val("[-]").html("Please select"));
       $.each(msg.d, function() {
          $("#ddlLanguage").append($("").val(this['Value']).html(this['Text']));
       });
     },
     error: function() {
      alert("An error has occurred during processing your request.");
     }
  });
});
收获园豆:20
悟行 | 专家六级 |园豆:12559 | 2012-05-14 11:11
其他回答(1)
0

楼上的赞同。

icepy | 园豆:587 (小虾三级) | 2012-05-14 13:39
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册