mazurva/yii2-nestable2

使用 nestable2 插件实现的 Yii 2.0 嵌套集合行为。

安装: 47

依赖: 1

建议者: 0

安全性: 0

星标: 1

关注者: 2

分支: 0

开放问题: 0

语言:JavaScript

类型:yii2-extension

v1.0 2021-11-10 23:41 UTC

This package is auto-updated.

Last update: 2024-08-28 08:43:34 UTC


README

使用 jquery.nestable2 插件实现的 Yii 2.0 嵌套集合行为。

tree

安装

安装此扩展的首选方式是通过 composer

运行

$ php composer.phar require mazurva/yii2-nestable2 "dev-master"

或在您的 composer.json 文件的 require 部分中添加

"mazurva/yii2-nestable2": "dev-master"

使用方法

确保您已正确地将 NestedSetsBehavior (creocoder/yii2-nested-sets) 附接到模型上。然后通过附加提供的操作到控制器中添加节点移动处理程序;

use mazurva\nestable2\widgets\Nestable;

class yourClass extends Controller
{
    public function actions() {
        return [
            'nodeMove' => [
                'class' => 'mazurva\nestable2\actions\NodeMoveAction',
                'modelName' => TreeModel::className(),
            ],
        ];
    }

然后在视图中渲染小部件;

echo Nestable::widget([
    'type' => Nestable::TYPE_WITH_HANDLE,
    'query' => TreeModel::find()->where([ top of tree ]),
    'modelOptions' => [
        'name' => 'name'
    ],
    'pluginEvents' => [
        'change' => 'function(e) {}',
    ],
    'pluginOptions' => [
        'maxDepth' => 7,
    ],
]);

您可以从 query 提供一个 ActiveQuery 对象来构建树,或者也可以提供一个项目列表;

    ...
    'items' => [
        ['content' => 'Item # 1', 'id' => 1],
        ['content' => 'Item # 2', 'id' => 2],
        ['content' => 'Item # 3', 'id' => 3],
        ['content' => 'Item # 4 with children', 'id' => 4, 'children' => [
            ['content' => 'Item # 4.1', 'id' => 5],
            ['content' => 'Item # 4.2', 'id' => 6],
            ['content' => 'Item # 4.3', 'id' => 7],
        ]],
    ],

modelOptions['name'] 应该保存一个属性名称,该名称将用于在列表中的项上命名。您还可以提供未命名的 function($model) 来构建您自己的内容字符串。

提供一个 pluginEvents['change'] 并包含一些 JavaScript 代码以捕获由 jquery.nestable 插件触发的更改事件。The pluginOptions 接受原始 jquery.nestable 插件的所有选项。