使用Socket IO进行Jstree延迟加载
Jstree lazy loading using Socket IO
我看到过使用jquery ajax的请求响应进行延迟加载,但没有任何方法可以使用Socket IO延迟加载节点数据吗?例如,我想要这样的
$("#tree").jstree({
"core": {
"data": function(data){
socket.on("node",function(node){
data = node;
})
}
}
});
每次单击时,我都可以调用数据回调来设置节点。对此有什么想法吗?期待中的感谢。
我不知道Socket IO,但我确信你用jstree做得不对:下面是你的函数应该是什么样子的:
function(currentNode, callback){
//we got it called twice, prolly because of angular
if(currentNode.id=='#'){
var me = this;
// perform a request with your framework here and call this once you have your data, '#' mean we're loading the root nodes
var nodes = <your data>
callback.call(me, nodes);
}else{
var me = this;
// we're loading child nodes
// same as before ask the nodes to the server then call the callback with the data loaded.
var nodes = <your data>
callback.call(me, nodes)
}
}
注意:"this"是树实例。
这有帮助吗?
var ws = new WebSocket("ws://xxxx.xx/xxx/");
ws.onopen = function () {
ws.onmessage = function (evt) {
$("#codeeditor").jstree({
"core": {
"data": {
"data": function(data){
data = evt.data;
}
}
}
});
};
};
此外,还需要一些保持WebSocket始终连接的方法,我在这里没有展示。
相关文章:
- 延迟加载jquery后替换$(document).ready(function)
- 延迟加载背景图像时防止双重请求
- 延迟加载 脚本加载和/或执行
- 使jquery延迟加载插件在视口内工作
- 如何在水平滚动 Jquery 上实现延迟加载
- 如何使用angularjs延迟加载谷歌jsapi图表
- 使用requirejs对延迟加载成员模块进行Typescript
- 淘汰具有延迟加载的多选下拉列表
- Kendo UI树视图中的延迟加载(带缓存)
- 使用Twitter引导程序's Scrollspy到延迟加载(滚动加载)异步JavaScript
- Javascript客户端从ASP.NET MVC后端延迟加载模型
- 在featherlight.js中延迟加载iFrame
- 如何包含多个JS文件-延迟加载javascript
- 使用筛选延迟加载项目
- AngularJS正在等待CSS延迟加载
- 卸载/销毁角延迟加载组件
- 使用Socket IO进行Jstree延迟加载
- 如何在文本上实现延迟加载
- 延迟加载js-how
- jsTree v.3使用ajax调用延迟加载