本文介绍了在淘汰赛中嵌套的arraylist绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 此函数绑定孔类别,但我不会绑定单个类别子类。 <! - ko foreach:{data:ParentCatagories,as:' parent'} - > < img data-bind =attr:{alt:parent.CategoryName,src:parent.CategoryImage} /> <! - ko foreach:{data:$ parent.getsubCatagories(parent.CategoryId) ,as:'child'} - > <! - / ko - > self.cols = ko.observableArray(); self.getsubCatagories = function(obj){ $ .ajax({ url:'/ api / Catagory', cache: false, 类型:'GET', contentType:'application / json; charset = utf-8', 数据:{CatId:obj}, 成功:函数(数据){ alert(数据。长度); $ .each(数据,函数(键,值){ Catagory.CategoryName = value.CategoryName; Catagory。 parentId = value.parentId; Catagory.PostCount = value.PostCount; Catagory.CategoryImage = value.CategoryImage; Catagory.CategoryChangeSource = 城市; Catagory.CategoryId = value.CategoryId; self.cols.push(value); }); } }); 返回self.cols; }; This function bind hole catagory but i wont to bind a single catagory subcatagory.<!-- ko foreach: {data: ParentCatagories ,as :'parent'} --> <img data-bind="attr:{alt: parent.CategoryName, src: parent.CategoryImage}" /> <!-- ko foreach: {data: $parent.getsubCatagories(parent.CategoryId) ,as: 'child' } --> <!-- /ko --> self.cols = ko.observableArray(); self.getsubCatagories = function (obj) { $.ajax({ url: '/api/Catagory', cache: false, type: 'GET', contentType: 'application/json; charset=utf-8', data: { CatId: obj }, success: function (data) { alert(data.length); $.each(data, function (key, value) { Catagory.CategoryName = value.CategoryName; Catagory.parentId = value.parentId; Catagory.PostCount = value.PostCount; Catagory.CategoryImage = value.CategoryImage; Catagory.CategoryChangeSource = "City"; Catagory.CategoryId = value.CategoryId; self.cols.push(value); }); } }); return self.cols; };推荐答案 parent.getsubCatagories(parent.CategoryId) ,as:'child'} - > <! - / ko - > self.cols = ko.observableArray(); self.getsubCatagories = function(obj){ parent.getsubCatagories(parent.CategoryId) ,as: 'child' } --> <!-- /ko --> self.cols = ko.observableArray(); self.getsubCatagories = function (obj) { .ajax({ url:'/ api / Catagory', cache:false, 类型:'GET', contentType:'application / json; charset = utf-8', 数据:{CatId:obj}, 成功:函数(数据){ alert(数据。长度); .ajax({ url: '/api/Catagory', cache: false, type: 'GET', contentType: 'application/json; charset=utf-8', data: { CatId: obj }, success: function (data) { alert(data.length); .each(数据,函数(键,值){ Catagory.CategoryName = value.CategoryName; Catagory.parentId = value.parentId; Catagory.PostCount = value.PostCount; Catagory.CategoryImage = value.CategoryImage; Catagory.CategoryChangeSource =City; Catagory.CategoryId = value.CategoryId; self.cols.push(value); }); } }); 返回self.cols; }; .each(data, function (key, value) { Catagory.CategoryName = value.CategoryName; Catagory.parentId = value.parentId; Catagory.PostCount = value.PostCount; Catagory.CategoryImage = value.CategoryImage; Catagory.CategoryChangeSource = "City"; Catagory.CategoryId = value.CategoryId; self.cols.push(value); }); } }); return self.cols; }; 这篇关于在淘汰赛中嵌套的arraylist绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-13 16:49