Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
308 views
in Technique[技术] by (71.8m points)

javascript - nickperkinslondon角树视图expand_all()问题(nickperkinslondon angular treeview expand_all() problems)

I'm using this angular treeview project:(我正在使用这个有角度的Treeview项目:)

https://github.com/nickperkinslondon/angular-bootstrap-nav-tree(https://github.com/nickperkinslondon/angular-bootstrap-nav-tree) I think that this treeview haven't got functions to do searches over treeview, so I implemented mine using a form to write the label to find.(我认为该树视图没有功能可以对树视图进行搜索,因此我使用表单来编写标签以实现查找。) <form name="searchForm" novalidate style="margin-bottom: 50px"> <div> <input ng-model="search" type="text" class="form-control" placeholder="Buscar..." name="searchTerm" required /> </div> </form> This form has a .watch to detect when the user writes some text:(此表单具有.watch来检测用户何时写入一些文本:) $scope.$watch('search', function(newTerm, oldTerm) { filteredResponse = !newTerm ? response : updateFilteredResponse(normalize(newTerm)); updateTree(); }, true); The function 'updateFilteredResponse' filter the nodes with label containing newTerm over original data set (read from json) and returns an array with the items to show in treeview.(函数'updateFilteredResponse'过滤带有原始数据集(从json读取)上包含newTerm的标签的节点,并返回一个包含要在treeview中显示的项目的数组。) The 'updateTree' function use this array and transform my custom items in the array to treeview items to add to the treeview.('updateTree'函数使用此数组,并将数组中的自定义项转换为treeview项,以添加到treeview中。) This items are added to $scope.tree_data = [];(此项添加到$ scope.tree_data = [];) And this array is the one that uses abn-tree directive:(这个数组是使用abn-tree指令的数组:) <abn-tree tree-data="tree_data" tree-control="my_tree" ng-if="loaded" expand-level = "2"></abn-tree> This part is working fine.(这部分工作正常。) My problem comes when the result treeview is shown at screen, the treeview always appears completely collapsed.(当屏幕上显示结果树形视图时,我的问题来了,树形视图总是看起来完全折叠了。) If I put a button similar to the library example code like this:(如果我按下类似于库示例代码的按钮,如下所示:) <div style="vertical-align:top"> <button ng-click="my_tree.expand_all()" class="btn btn-default btn-sm">Expand All</button> </div> And declaring this in the controller as the example:(并以控制器为例进行声明:) var tree; $scope.my_tree = tree = {}; When the users click the button to expand all over the search results, it works fine.(当用户单击按钮以扩展整个搜索结果时,它可以正常工作。) By I need to auto-expand the treeview after a search, and remove the expand-all-button.(我需要在搜索后自动展开treeview,并删除全部展开按钮。) For that, I'm trying to call my_tree.expand_all() in my controller.(为此,我试图在控制器中调用my_tree.expand_all()。) I tried different calls:(我尝试了不同的电话:) $scope.my_tree.expand_all(); tree.expand_all(); In different parts of my controller and my html (using ngIf and onload directives).(在控制器和html的不同部分(使用ngIf和onload指令)。) Even I tried to do a 'watch' over $scope.my_tree for try to use the expand_all() function when var is prepared but I always have the same error:(即使我尝试在$ scope.my_tree上执行“监视”操作,以在准备var时尝试使用expand_all()函数,但我始终遇到相同的错误:) $scope.my_tree.expand_all is not a function Can anyone help me with that please?(有人可以帮我吗?)   ask by AliMola translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can put expand_all() function into setTimeout function as below.(您可以按以下方式将expand_all()函数放入setTimeout函数中。)

setTimeout(function() { $scope.my_tree.expand_all(); $scope.$digest(); }, 0); It have to do because it take some delay time while binding data to treeview.(之所以必须这样做,是因为将数据绑定到Treeview时需要一些延迟时间。)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...