码迷,mamicode.com
首页 > 编程语言 > 详细

select绑定json数组对象 asp.net

时间:2015-10-12 00:38:21      阅读:169      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!