美文网首页
search Tree view node

search Tree view node

作者: luke_skywalker | 来源:发表于2018-08-04 15:57 被阅读0次
    function search_node(){
        var search_value = $("#search_sel").find("option:selected").text();
        var index =  $("#search_sel").find("option:selected").val()
        var search_path = list_file[index];
        console.log("search tree ...")
         var initSelectableTree = function() {
              return $('#left_con').treeview({
                data: data_1,
                multiSelect: false,
                onNodeSelected: function(event, node) {
                    console.log(node.text+"was selected.")
                    if(search_path){
                       
                        arrange_data_ajax(search_path);
                    }
                  //$('#selectable-output').prepend('<p>' + node.text + ' was selected</p>');
                },
                onNodeUnselected: function (event, node) {
                 // $('#selectable-output').prepend('<p>' + node.text + ' was unselected</p>');
                }
              });
            };
            var $selectableTree = initSelectableTree();
    
            var findSelectableNodes = function() {
              return $selectableTree.treeview('search', [ search_value, { ignoreCase: false, exactMatch: true } ]);
            };
            var selectableNodes = findSelectableNodes();
        /*  $("#search_sel").on('keyup', function (e) {
              selectableNodes = findSelectableNodes();
             // $('.select-node').prop('disabled', !(selectableNodes.length >= 1));
            }); */
            var nodes_index=0;
            for (var k=0;k<selectableNodes.length;k++){
                console.log("selectableNodes:"+selectableNodes[k].file_path);
                if(selectableNodes[k].file_path == search_path){
                    console.log("K:"+k);
                    nodes_index = k;
                    break;
                }
            }
            $('#btn_go').on('click', function (e) {
                
              $selectableTree.treeview('selectNode', [ selectableNodes[k], { silent: false }]);
            });
            console.log("search_path:"+search_path);
           /*   $('#btn_go').on('click', function (e) {
              $selectableTree.treeview('selectNode', [ selectableNodes[0], { silent: false }]);
            }); */
    }
    $("#btn_go").click(function(){
        search_node();
    })
    /*============================================================================*/
    for(int i=0;i<TreeView1.Nodes.Count;i++) {
        if(TreeView1.Nodes[i]==TextBox1.Text){ 
            string index1=TreeView1.Nodes[i].GetNodeIndex();//取得index 
            TreeView1.SelectedNodeIndex=index1; 
        }
    }
    
    function searchTree(element, matchingTitle){
         if(element.title == matchingTitle){
              return element;
         }else if (element.children != null){
              var i;
              var result = null;
              for(i=0; result == null && i < element.children.length; i++){
                   result = searchTree(element.children[i], matchingTitle);
              }
              return result;
         }
         return null;
    }
    
    function search_tree(treeID,tree_data,search_value){
        console.log("using Search function!");
        var searchedTree = treeID;
        var $searchableTree = $(treeID).treeview({
              data: tree_data
            });
        var search = function() {
              
              var pattern = search_value;
              var options = {
                ignoreCase: true,
                exactMatch: true,
                revealResults: true    //倒数匹配
              };
              var results = $searchableTree.treeview('search', [pattern, options]);
              console.log("results length:"+results.length+results.text);
            }
        
        if(searchedTree=="#treeview1"){
            $('#btn_gol').on('click', search); 
            console.log("click left go!");
        }else{
            $('#btn_gor').on('click', search); 
            console.log("click right go!");
        }
    }
    

    相关文章

      网友评论

          本文标题:search Tree view node

          本文链接:https://www.haomeiwen.com/subject/pwwlvxtx.html