Angular Jstree搜索插件



在我当前的项目中我使用ngjstree。

如何将<input type"search">连接到Angularjs的Jstree进行实时搜索?

查看

<input type"search">
<div id="js-tree" js-tree="treeConfig" ng-model="tags"></div>

控制器

$scope.treeConfig = {
    "plugins": ["checkbox", "search"],
    "core": {
      "check_callback": true,
      "multiple": false,
   }
};
$scope.data = [
  {
    'id': 1,
    'text': 'node 1'
  },
  {
    'id': 2,
    'text': 'node 2'
  }

我解决了问题。

html

<input type="text" ng-model="search" ng-keyup="applySearch(search)" placeholder="search">
<div id="js-tree" js-tree="treeConfig" ng-model="tags" tree="treeInstance"></div>

JS

$scope.applySearch = function (){
    var to = false;
    if(to) {
       clearTimeout(to);
    }
    to = setTimeout(function () {
       if($scope.treeInstance) {
          $scope.treeInstance.jstree(true).search($scope.search);
       }
    }, 250);
};

最新更新