Select2下拉框绑定数据

  //初始化select2控件
        $(document).ready(function () {
            $("#XueYuan").select2({ placeholder: '请选择' });
        });


  $.ajax({
            url: "/XSSSPGYPY/XSPY/SelectXueYuan",
            type: "get",
            dataType: "json",
            success:function (data)
            {
                XueYuan.options.add(new Option("请选择", 0));
                for (var i=0;i
                {
                    $("#XueYuan").append("" + data[i].XueYuanMC + "");
                }
            }

        });//查询学院



$("#c01-select").select2({
  ajax: {
    url: "data.json",
    dataType: 'json',
    delay: 250,
    data: function (params) {
      return {
        q: params.term,
      };
    },
    processResults: function (data) {
      return {
        results: data
      };
    },
    cache: true
  },
  escapeMarkup: function (markup) { return markup; }, 
  minimumInputLength: 1,
  templateResult: formatRepo, 
  templateSelection: formatRepoSelection 
});

你可能感兴趣的:(Jquery)