jsTree搜索排序向上向下
var _node = null, _all_match = 0, _current_match = 0;
$(document).ready(function() {
$('#area_setting_ou_tree').jstree({
'core' : {
'data' : {
"url" : "url",
"method" : "POST",
"dataType" : "json"
},
"multiple" : false,
"check_callback" : true,
"animation" : 0
},
'plugins': [
"sort",
"search",
"types"
],
'sort' : function(a, b) {
return this.get_type(a) === this.get_type(b) ? (this.get_text(a) > this.get_text(b) ? 1 : -1) : (this.get_type(a) >= this.get_type(b) ? 1 : -1);
},
'search' : {
'search_leaves_only' : true,
'search_callback' : function(string,node){
if(string !== '' && node.type === 'staff' && node.text.toLocaleLowerCase().match(string.toLocaleLowerCase())) {
_instance.open_all();
$('#' + node.id).addClass('jstree-search');
}else {
$('#' + node.id).removeClass('jstree-search');
}
}
},
'types' : {
"staff" : {
"icon" : "url"
},
"ou_end" : {
"icon" : "url"
},
"ou_not_end" : {
"icon" : "url"
}
}
}).on('search.jstree', function() {
var _selected_node = $('#area_setting_ou_tree ul li .jstree-search');
if(_selected_node.length === 0) return; var _instance = $('#area_setting_ou_tree').jstree(true); _all_match = _selected_node.length;
$('#all_selected').text(_all_match);
_current_match = 1;
$('#current_selected').text(_current_match); var node_id = '';
_selected_node.each(function(index, dom) {
node_id = $(this).attr('id');
if(index === 0) {
_instance.select_node(node_id);
$('#' + node_id).addClass('jstree-search');
location.hash = '#' + node_id;
}
_node.add(node_id);
});
}); var _instance = $('#area_setting_ou_tree').jstree(true);
/*
* search event for Tree
*/
var area_setting_ou_tree_to = false;
$('#area_setting_ou_tree_search').keyup(function () {
setTimeout(function() {
_all_match = 0;
_current_match = 0;
$('#current_selected').text(0);
$('#all_selected').text(0);
$('#area_set_main').html('');
_node = null;
_node = new DoubleLinkedList();
var _instance = $('#area_setting_ou_tree').jstree(true);
_instance.deselect_all();
$('#selected_message').css('visibility','visible');
$('#pre_selected').prop('disabled',false);
$('#next_selected').prop('disabled',false); if(area_setting_ou_tree_to) { clearTimeout(area_setting_ou_tree_to); }
area_setting_ou_tree_to = setTimeout(function () {
var company_department_tree_search_val = $('#area_setting_ou_tree_search').val();
$('#area_setting_ou_tree').jstree(true).search(company_department_tree_search_val);
}, 250); if($('#area_setting_ou_tree_search').val() === '') {
$('#selected_message').css('visibility','hidden');
$('#pre_selected').prop('disabled',true);
$('#next_selected').prop('disabled',true);
$('.jstree-search').removeClass('jstree-search');
$('#area_set_main').html('');
}
}, 200);
}); /*
* next step for Tree
*/
$('#next_selected').on('click', function(){
if(_node.size() === 0) return;
var _instance = $('#area_setting_ou_tree').jstree(true); // selected node is not search results
var _current_selected = null;
if(_node.find(_instance.get_selected()[0])) {
_current_selected = _node.find(_instance.get_selected()[0]);
} else {
_current_selected = _node.getHead();
_current_match = 0;
} if(_current_selected.next) {
var _temp = _current_selected.next.element;
_instance.deselect_all();
_instance.select_node(_temp);
location.hash = '#' + _temp;
showInstitutionByClickTree(_instance.get_type(_temp), _temp);
_current_match += 1;
$('#current_selected').text(_current_match);
} else {
//跳转到第一个
_current_match = 1;
var _temp = _node.getHead().next.element;
_instance.deselect_all();
_instance.select_node(_temp);
location.hash = '#' + _temp;
//showInstitutionByClickTree(_instance.get_type(_temp), _temp);
$('#current_selected').text(_current_match);
} });
/*
* previous step for Tree
*/
$('#pre_selected').on('click', function(){
if(_node.size() === 0) return;
var _instance = $('#area_setting_ou_tree').jstree(true); // selected node is not search results
var _current_selected = null;
if(!_node.find(_instance.get_selected()[0])) {
_current_selected = _node.findLast();
_current_match = _node.size();
var _temp = _current_selected.element;
_instance.deselect_all();
_instance.select_node(_temp);
location.hash = '#' + _temp;
showInstitutionByClickTree(_instance.get_type(_temp), _temp);
$('#current_selected').text(_current_match);
return;
} _current_selected = _node.find(_instance.get_selected()[0]);
if(_current_selected.previous != _node.getHead()) {
var _temp = _current_selected.previous.element;
_instance.deselect_all();
_instance.select_node(_temp);
_current_match -= 1;
$('#current_selected').text(_current_match);
} else {
//跳转到最后一个
_current_selected = _node.findLast();
_current_match = _node.size();
var _temp = _current_selected.element;
_instance.deselect_all();
_instance.select_node(_temp);
$('#current_selected').text(_current_match);
}
});
});
双链表
function Node(element){
this.element = element;
this.next = null;
this.previous = null;
}
function DoubleLinkedList(){
this._head = new Node("This is Head Node.");
this._size = 0;
}
DoubleLinkedList.prototype.getHead = function(){
return this._head;
};
DoubleLinkedList.prototype.isEmpty = function(){
return this._size === 0;
};
DoubleLinkedList.prototype.size = function(){
return this._size;
};
DoubleLinkedList.prototype.findLast = function(){
var currNode = this.getHead();
while(currNode.next){
currNode = currNode.next;
}
return currNode;
};
DoubleLinkedList.prototype.add = function(item){
if(item == null)
return null;
this.insert(item);
};
DoubleLinkedList.prototype.remove = function(item){
if(item) {
var node = this.find(item);
if(node == null)
return ;
if (node.next === null) {
node.previous.next = null;
node.previous = null;
} else{
node.previous.next = node.next;
node.next.previous = node.previous;
node.next = null;
node.previous = null;
}
this._size--;
}
};
DoubleLinkedList.prototype.find = function(item){
if(item == null)
return null;
var currNode = this.getHead();
while(currNode && currNode.element !== item){
currNode = currNode.next;
}
return currNode;
};
DoubleLinkedList.prototype.insert = function(newElement, item){
var newNode = new Node(newElement);
var finder = item ? this.find(item) : null;
if(!finder){
var last = this.findLast();
newNode.previous = last;
last.next = newNode;
}
else{
newNode.next = finder.next;
newNode.previous = finder;
finder.next.previous = newNode;
finder.next = newNode;
}
this._size++;
};
DoubleLinkedList.prototype.dispReverse = function(){
var currNode = this.findLast();
while(currNode != this.getHead()){
console.log(currNode.element);
currNode = currNode.previous;
}
};
DoubleLinkedList.prototype.display = function(){
var currNode = this.getHead().next;
while(currNode){
console.log(currNode.element);
currNode = currNode.next;
}
};
jstree:版本号-3.0.9
API地址:https://www.jstree.com/api/
数据:ajax后台生成
数据结构:双链表
jsTree搜索排序向上向下的更多相关文章
- 搜索实时个性化模型——基于FTRL和个性化推荐的搜索排序优化
本文来自网易云社区 作者:穆学锋 简介:传统的搜索个性化做法是定义个性化的标签,将用户和商品通过个性化标签关联起来,在搜索时进行匹配.传统做法的用户特征基本是离线计算获得,不够实时:个性化标签虽然具有 ...
- YII关联字段并带搜索排序功能
1.简介 从接触yii框架到现在已经快有两个月了,但是自己对yii框架的了解程度并不是很深,并没有系统地去学习,仅仅只是在做项目的时候遇到不懂得知识才去翻手册. 在上一个项目中因为需要将关联的表的字段 ...
- 重写 final关键字 多态调用子类特有的属性及行为(向上向下转型)
1.override 重写:在继承中,子类与父类方法名相同,参数列表相同,的方法叫重写,与返回值有关; 主要应用于系统升级. 2.final 关键字: 可修饰:1.类-->被修饰后该类不能被继 ...
- 带搜索框的jQuery下拉框插件
由于下拉框的条数有几十个,于是打算找一个可以搜索查找功能的下拉框,刚开始在网上看了几个,都是有浏览器兼容性问题,后来看到这个“带搜索框的jQuery下拉框美化插件 searchable”,看演示代码简 ...
- Atitit.获得向上向下左的右的邻居的方法 软键盘的设计..
Atitit.获得向上向下左的右的邻居的方法 软键盘的设计.. Left right可以直接使用next prev.. Up down可以使用pix 判断...获得next element的posit ...
- 带搜索框的select下拉框
利用select2制作带有搜索功能的select下拉框 1.引入线上css和js <link href="https://cdnjs.cloudflare.com/ajax/libs/ ...
- Object类 任何类都是object类的子类 用object对象接收数组 object类的向上向下转型
任何类都是object类的子类 用object对象接收数组 object类的向上向下转型
- WPF中类似使用tab键功能,可以向上向下定位
原文:WPF中类似使用tab键功能,可以向上向下定位 private void tbYyrs_KeyUp(object sender, KeyEventArgs e) { UIElement elem ...
- 【python】Leetcode每日一题-搜索排序数组2
[python]Leetcode每日一题-搜索排序数组2 [题目描述] 已知存在一个按非降序排列的整数数组 nums ,数组中的值不必互不相同. 在传递给函数之前,nums 在预先未知的某个下标 k( ...
随机推荐
- 第九课,T语言数组的定义与访问(版本5.0)
数组的定义与访问 数组是一系列数据的集合,可以存储大量数据,通过数组的下标.key,可以实现对数据的快速访问. 为什么要使用数组呢? 如果您有一个项目列表(例如汽车品牌列表),在单个变量中存储这些品牌 ...
- python 列表操作
列表的基本操作示例展示: append 功能:列表追加元素 name = ['sd','dfdf','drer'] name.append('sdsd') 返回结果:name ['sd', 'dfdf ...
- osx 文本编辑工具下载地址Sublime Text 3
下载地址: http://www.sublimetext.com/3 Sublime Text 是一个代码编辑器(Sublime Text 3是收费软件,但可以无限期试用),也是HTML和散文先进的文 ...
- 10 个最适合 Web 和 APP 开发的 NodeJS 框架
在浏览器以外运行 JavaScript 对于 JavaScript 爱好者来说非常神奇,同时也肯定是 web 应用程序开发界最受欢迎的进步之一.全球各地的开发者张开双臂拥抱 NodeJS. 对于新手来 ...
- remove() 方法的兼容问题
一直以为jq的remove()方法是兼容的,今天才发现,原来ie的写法不一样,特作此记录. removeNode方法的功能是删除一个节点,语法为node.removeNode(false)或者node ...
- HackerRank "Kruskal (MST): Really Special Subtree"
Kruskal Algorithm is based on Union-Find - quite intuitive. #include <vector> #include <ios ...
- 一个简单的CORBA例子
因为对CORBA分析的需要,这里写一个简单的CORBA例子.从JDK1.2开始,JDK中集成了ORB的实现,本例子使用了JDK1.7,对于JDK1.2+应该都没有问题.这个例子实现一个简单的加减乘除的 ...
- [ActionScritp 3.0] 使用LocalConnection建立通信
包 flash.net 类 public class LocalConnection 继承 LocalConnection → EventDispatcher → Object 语言版本: Acti ...
- ORACLE 创建作业JOB例子
--1.plsql中学习job --学习job --建表 create table test_job(para_date date); commit; insert into test ...
- Android API Guides 学习笔记---Application Fundamentals(一)
今天开始学习google官网上的API guides ,主要读了Application Fundamentals这一章节,此章节介绍了一个App的基本组成,共包括四大部分内容. 1. App ...