[Yii2 Widget]FancytreeWidget树状结构
来源:互联网 发布:胡克霍根身体数据 编辑:程序博客网 时间:2024/05/16 13:40
1.树状结构页面显示效果如下图:
2.应用了插件FancytreeWidget (composer中安装wbraganca/yii2-fancytree-widget)
<?phpuse yii\helpers\ArrayHelper;use yii\helpers\Url;use yii\helpers\Html;use yii\web\JsExpression;echo \wbraganca\fancytree\FancytreeWidget::widget([ 'options' =>[ 'id' => 'table-fancytree', // 设置整体id 'source' => $data, // 树状结构数据 'extensions' => ['edit', 'table'], // 扩展, 可有: edit编辑, dnd拖拽等js效果 'edit' => [ // 编辑js 'inputCss' => ['minWidth' => '8em'], 'triggerStart' => ["f2", "dblclick", "shift+click", "mac+enter"], // 进入编辑模式方法: f2键,双击,shift+单机,enter 'beforeEdit' => new JsExpression('function(event, data){ }'), 'edit' => new JsExpression('function(event, data){ }'), 'beforeClose' => new JsExpression('function(event, data){ }'), 'save' => new JsExpression('function(event, data){ }'), 'close' => new JsExpression('function(event, data){ // 写jq代码 已实例化JsExpression方式 // event是指当前执行方法, data是指当前编辑行对象 var th = data.node; node = $("#table-fancytree").fancytree("getActiveNode"); // 获取 'class=fancytree-active'中所有对象 oldName = data.orgTitle; // 修改之前名字 newName = data.node.title; // 要修改的名字 child = th.data.child ? 1 : 0; id = node.key; if (oldName == newName || !newName) { return false; } update(id, newName, oldName, child, th); // 引入js文件后可直接调用方法 }'), ], // 点击查找子集节点 注意: 要触发lazyLoad 在$data数组中要设置'lazy' => true // lazyLoad方法中必须要有 data.result, 其值为一个对象, 对象中有一个请求url后面跟请求参数, 该url返回jesn串(其实就是发送一个ajax, 例如: [{"title":"\u5317\u4eac\u5e02","key":"2","folder":true,"expanded":false,"lazy":true}]) 'lazyLoad' => new JsExpression('function(event, data){ var id = data.node.key; url = "' . Url::toRoute(["district/get-san"], true) . '"; data.result = {url: "" + url + "?id=" + id + ""}; }'), 'table' => [ 'indentation' => 20, 'nodeColumnIdx' => 0 ], // 渲染列 'renderColumns' => new JsExpression('function(event, data) { var node = data.node; var $tdList = $(node.tr).find(">td"); $tdList.eq(1).text(node.key); var btnEdit = \'\'; var btnRemove = \'<a href="' . Url::to(['YOUR_URL/delete']) . '&id=\' + node.key + \'" title="Delete" data-confirm="Are you sure you want to delete this item?" data-method="post" data-pjax="0"><span class="glyphicon glyphicon-trash"></span></a>\'; // 一些编辑类按钮 $tdList.eq(1).html(btnEdit + " " + btnRemove).addClass("align-center align-middle"); }'), ] ]);?><div class="table-responsive"> <table id="table-fancytree" class="table table-bordered"> <colgroup> <col width="*"></col> <col width="80px"></col> </colgroup> <thead> <tr> <th>区域</th> <th class="align-center align-middle">操作</th> </tr> </thead> <tbody> <tr> <td></td> <td></td> </tr> </tbody> </table></div><?php// 引入js文件$this->registerJsFile("@web/js/district.js", [ 'depends' => [\service\assets\AppAsset::className()]]);?>
进行一下资源补充:
Yii2 Fancytree Widget
https://github.com/wbraganca/yii2-fancytree-widget
Fancytree Demo
http://wwwendt.de/tech/fancytree/demo/
阅读全文
0 0
- [Yii2 Widget]FancytreeWidget树状结构
- Yii2-ueditor-widget使用
- Yii2自定义Widget,百度编辑器
- yii2 widget实现筛选记录
- 树状结构
- 树状结构
- 树状结构
- [Yii2 Widget]sortinput的简单使用
- Yii2.0-Widget小部件制作
- [widget] -- yii2小部件高级使用
- yii2 目录结构
- yii2.0目录结构
- Yii2目录结构
- YII2 增加自定义目录结构
- Yii2.0目录结构记录
- Yii2 应用结构之模块
- Yii2为ActiveForm的widget组件设置属性
- Yii2 framework学习笔记(四) -- 第一个Widget
- [通过scikit-learn掌握机器学习] 02 线性回归
- C 自定义字符串输出
- Spiral Matrix II
- 18、使用 tf.app.flags 接口定义命令行参数
- C语言面向对象编程之一:封装与继承
- [Yii2 Widget]FancytreeWidget树状结构
- 19、TensorFlow 实现最近邻分类器(K=1)
- 过滤掉字符串中的非数字
- Leetcode350 Intersection of Two Arrays II &Leetcode Intersection of Two Arrays
- C语言面向对象编程之二:继承
- 20、TensorFlow 中 MNIST 数据集的使用
- 中山大学算法课程题目详解(第九周)
- TextView 跑马灯
- 自定义类型与内存对齐