zoukankan      html  css  js  c++  java
  • select绑定json数组对象 asp.net

    ashx处理页

        string JsonList = "[";
               IList<Models.Channel> ilist = BLL.ChannelManager.GetAllChannels();
               List<Models.Channel> list = PublicCS.IListToList(ilist);/// IList转化为List
               JsonList += "{id:0,ChannelName:'顶级栏目'},";
               foreach (Models.Channel channel in list)
               {
                    JsonList += "{id:" + channel.Id.ToString() +",ChannelName:'" + channel.ChannelName + "'},";
               }
               JsonList = JsonList.Substring(0, JsonList.Length - 1);
               JsonList += "]";
           context.Response.Write("[{"message":"成功","ActionType":"" + action + "","JsonList":"" + JsonList + "","status":"success"}]");
               context.Response.End();
              return;
      /// <summary>
        /// IList转化为List
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="list"></param>
        /// <returns></returns>
        public static List<T> IListToList<T>(IList<T> list)
        {
            T[] array = new T[list.Count];
            list.CopyTo(array, 0);
            return new List<T>(array);
        } 

    html页面

     <li><label>父级栏目</label><select id="ParentID">
         </select>
         </li>

    JS

     var JsonList={};
         JsonList =eval(data[0].JsonList);//将json数组转化为json对象
    
         for(var i=0;i<JsonList.length;i++)//将json对象 绑定到select
         {
            $("#ParentID").append("<option value='"+JsonList[i].id+"'>"+JsonList[i].ChannelName+"</option>");
         }
  • 相关阅读:
    mysql数据库 --数据类型、约束条件
    并发编程 --线程
    并发编程 --进程
    MySQL数据库 --基础
    网络编程之 TCP-UDP的详细介绍
    网络编程之 OSI七层协议
    python 元类、单例模式
    python 面向对象_多态、内置方法、反射
    Python 面向对象_继承、组合
    简单工厂设计模式
  • 原文地址:https://www.cnblogs.com/qigege/p/4870488.html
Copyright © 2011-2022 走看看