zoukankan      html  css  js  c++  java
  • easyui-combobox 传递参数到后台获取json来绑定选项

    此文学习 djk8888的方法

    //jq请求后台方法

    $.getJSON("/ProjectItems?comid=" + companyid,
    function (json) {
    alert(json);
    $("#projectid").combobox({
    data: json,//获取要显示的json数据
    valueField: 'id',
    textField: 'text',
    });
    });

    //异步请求方法

    public ActionResult ProjectItems()
    {
    int comid = Request.GetParamMvc<int>("comid");
    List<CompanyProject> pros = companyproject.GetModelList(o => o.parentid == comid).ToList();
    string json = SubjectJson(pros);
    return Content(json);
    }

    //list集合转为combox能绑定的json数据格式

    public string SubjectJson(List<CompanyProject> pros)
    {
    var subject = pros;
    if (subject != null && subject.Any())
    {
    string jsonData = "[";
    subject.ForEach(b =>
    {
    jsonData += "{";
    jsonData += ""id":"" + b.id + "",";
    jsonData += ""text":"" + b.name + """;
    jsonData += "}";
    jsonData += ",";
    });
    jsonData = jsonData.Substring(0, jsonData.Length - 1);//去掉末尾的 , 逗号
    jsonData += "]";
    return jsonData;
    }
    return string.Empty;
    }

  • 相关阅读:
    bootStrap-treeview插件
    UML常用图的几种关系的总结
    RFC中文文档
    继承:重新使用接口
    Java8向后兼容
    Java8 时间调节器
    Java8 ChronoUnits枚举
    BigDecimal.divide方法
    java.lang.Double.byteValue() 方法
    事件处理是什么?
  • 原文地址:https://www.cnblogs.com/wuyiran/p/7216355.html
Copyright © 2011-2022 走看看