Easyui-tree 加载json数据及loadFilter的使用
2016-09-20 09:54
417 查看
一、easyui tree基本使用
首先定义一个<ul>
Html代码
<ul id="tt"></ul>
easyui tree 加载json数据:
Js代码
$('tt').tree({
lines:true,//是否显示树线
url:'tree.json'
});
json数据要求的格式:下载
Json代码
[{
"id":1,
"text":"My Documents",
"children":[{
"id":11,
"text":"Photos",
"state":"closed",
"children":[{
"id":111,
"text":"Friend"
},{
"id":112,
"text":"Wife"
},{
"id":113,
"text":"Company"
}]
},{
"id":12,
"text":"Program Files",
"state":"closed",
"children":[{
"id":121,
"text":"Intel"
},{
"id":122,
"text":"Java"
},{
"id":123,
"text":"Microsoft Office"
},{
"id":124,
"text":"Games"
}]
},{
"id":16,
"text":"Actions",
"children":[{
"text":"Add",
"iconCls":"icon-add"
},{
"text":"Remove",
"iconCls":"icon-remove"
},{
"text":"Save",
"iconCls":"icon-save"
},{
"text":"Search",
"iconCls":"icon-search"
}]
},{
"id":13,
"text":"index.html"
},{
"id":14,
"text":"about.html"
},{
"id":15,
"text":"welcome.html"
}]
}]
其中iconCls表示的图标,这样数据就加载出来了。
二、loadFilter使用
loadFilter可以返回过滤后的数据进行展示
其使用格式:下载
Js代码
$('tt').tree({
url:'tree.json'
loadFilter:function(data){
//过滤操作
return newData;
}
});
例:我们从json数据查找text属性值为"Program Files"的树返回展示:下载
Js代码
$('tt').tree({
url:'tree.json'
loadFilter:function(data){
for(var i=0; i<data.length; i++){
if(data[i].text=="Program Files"){
// 定义一个数组
var newData = new Array();
newData.push(data[i]);
return newData;
}
}
return data;
}
});
这里我们可以看到我们使用了数组Array来存放过滤后的数据,这是因为easyui-tree加载json格式的原因,否则加载不出。
首先定义一个<ul>
Html代码
<ul id="tt"></ul>
easyui tree 加载json数据:
Js代码
$('tt').tree({
lines:true,//是否显示树线
url:'tree.json'
});
json数据要求的格式:下载
Json代码
[{
"id":1,
"text":"My Documents",
"children":[{
"id":11,
"text":"Photos",
"state":"closed",
"children":[{
"id":111,
"text":"Friend"
},{
"id":112,
"text":"Wife"
},{
"id":113,
"text":"Company"
}]
},{
"id":12,
"text":"Program Files",
"state":"closed",
"children":[{
"id":121,
"text":"Intel"
},{
"id":122,
"text":"Java"
},{
"id":123,
"text":"Microsoft Office"
},{
"id":124,
"text":"Games"
}]
},{
"id":16,
"text":"Actions",
"children":[{
"text":"Add",
"iconCls":"icon-add"
},{
"text":"Remove",
"iconCls":"icon-remove"
},{
"text":"Save",
"iconCls":"icon-save"
},{
"text":"Search",
"iconCls":"icon-search"
}]
},{
"id":13,
"text":"index.html"
},{
"id":14,
"text":"about.html"
},{
"id":15,
"text":"welcome.html"
}]
}]
其中iconCls表示的图标,这样数据就加载出来了。
二、loadFilter使用
loadFilter可以返回过滤后的数据进行展示
其使用格式:下载
Js代码
$('tt').tree({
url:'tree.json'
loadFilter:function(data){
//过滤操作
return newData;
}
});
例:我们从json数据查找text属性值为"Program Files"的树返回展示:下载
Js代码
$('tt').tree({
url:'tree.json'
loadFilter:function(data){
for(var i=0; i<data.length; i++){
if(data[i].text=="Program Files"){
// 定义一个数组
var newData = new Array();
newData.push(data[i]);
return newData;
}
}
return data;
}
});
这里我们可以看到我们使用了数组Array来存放过滤后的数据,这是因为easyui-tree加载json格式的原因,否则加载不出。
相关文章推荐
- Easyui-tree 加载json数据及loadFilter的使用
- Easyui-tree 加载json数据及loadFilter的使用
- 使用EasyUI的tree组件,叶子节点下会加载所有节点数据,形成死循环......
- PHP+MySQL+Easyui tree菜单从后台加载json数据(一)
- 使用easyui-combobox的data属性加载定义好在*.js文件中的JSON数据的问题
- ExtJS的FormPanel中的组件使用load加载远程的JSON数据的方法
- jquery easyui tree动态加载-服务端struts返回json数据
- easyui tree loadFilter的使用
- EasyUI DataGrid使用Json加载不了数据
- easyui中tree使用simpleData的形式加载数据
- 【原创】c#讲数据库数据转换为json格式(使用extjs,easyui中的datagrid)
- 使用Boost.PropertyTree处理XML、JSON和INI数据
- C#将datatable生成easyui的绑定tree 的json数据格式
- easyui中 combogrid控件的loadData方法加载本地数据
- c#将数据库数据转换为json格式(使用extjs,easyui中的datagrid)
- easyui使用Ajax提交表单,返回Json数据
- EASYUI TREEGRID异步加载数据实现方法
- easyui中的tree数据使用说明
- Java+oracle树查询实现easyui中tree使用的json
- Silverlight DataGrid使用WCF RIA Service实现Load-on-demand的数据加载