首页 > 编程语言 > 详细

select绑定json数组对象 asp.net

时间:2015-10-12 00:35:45      阅读:337      评论:0      收藏:0      [点我收藏+]

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>");
     }

 

select绑定json数组对象 asp.net

原文:http://www.cnblogs.com/qigege/p/4870488.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!