本文介绍了如何使用javascript从json对象附加超过millon记录到列表框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 在我的MVC Web应用程序中我调用Ajax并且在成功中我有Json对象,Json对象包含项目列表,列表的长度是61111项目但是当试图将这些项目逐个地使用循环附加到列表中时花了很长时间然后网页告诉我页面没有响应杀死或继续, 代码如下 step1: @ Html.ListBox(_ TAG_INFO,新的MultiSelectList(ViewBag.TAG_INFO_ID,ID,ITEM_ID,Model._TAG_INFO.Select(x => x.ID)),new {Multiple = multiple,@ id =TagsListbox}) - Step2: In My MVC Web Application I Call Ajax and In Success I have Json Object ,The Json Object Contains list of items ,the length of list is 61111 item but when Trying to append these items to the list one by one using loop it takes long time and then the web page tells me that the page unresponsive kill or continue,the code as followstep1: @Html.ListBox("_TAG_INFO", new MultiSelectList(ViewBag.TAG_INFO_ID, "ID", "ITEM_ID", Model._TAG_INFO.Select(x => x.ID)), new { Multiple = "multiple", @id = "TagsListbox" })--Step2:$.ajax({ cache: false, type: "POST", url: "@(Url.Action("GetTags", "TagPath"))", data: { "Service": service }, dataType: 'json', success: function (data) { $("#TagsListbox").empty(); for (var i = 0; i < data.objects.length; i++) { // $.each(data.objects, function (i, item) { var selected = ""; if (data.objects[i] != null) { if (data.objects[i]._IsSelected) { selected = "selected"; } var newOption = "<option value='" + data.objects[i].ID + "'" + " " + selected + ">" + data.objects[i].ITEM_ID + "</option>"; $("#TagsListbox").append(newOption); } // }); } }, error: function () { alert('@Resource._CantRetData'); } }); ----- step3: -----step3:[HttpPost] public JsonResult GetTags(string service) { string strAlert = string.Empty; List<TAG_INFO> objects = new List<TAG_INFO>(); int CurrentBusinessGroup = GetCurrentUserGroup().BUSINESS_GROUP_ID; List<TAG_INFO> _TAG_INFO; try { var FilteredTags =new List<TAG_INFO>(); if (service == "0" || service == null) //All selected { _TAG_INFO = db.TAG_INFO.Where(x => x.STATUS == ActiveStatus).ToList(); } else { _TAG_INFO = db.TAG_INFO.Where(x => x.SERVICE == service && x.STATUS == ActiveStatus).ToList(); } if (_TAG_INFO.Count > 0) { //objects.Add(new TAG_INFO() { ID = 0, ITEM_ID = Resource._AllTags }); foreach (var item in _TAG_INFO) { objects.Add(new TAG_INFO() { ID = item.ID, ITEM_ID = item.ITEM_ID + "-" + item.ITEM_SUB_ID, _IsSelected = false }); } } } catch (Exception ex) { strAlert = ex.ToString(); } //Return your JSON object JsonResult jsonResult = Json(new { objects = objects, strAlert = strAlert },JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; //return Json(new { objects = objects, strAlert = strAlert }); } 我的尝试: 我试图将超过Millon记录附加到listBox。What I have tried:I am trying to append More than Millon record to listBox.推荐答案 这篇关于如何使用javascript从json对象附加超过millon记录到列表框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
11-01 14:46