slatiusa/yii2-nestable 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

slatiusa/yii2-nestable

最新稳定版本:v1.2.1

Composer 安装命令:

composer require slatiusa/yii2-nestable

包简介

Yii 2.0 implementation of nested set behavior using jquery.nestable plugin.

README 文档

README

Yii 2.0 implementation of nested set behavior using jquery.nestable plugin.

Installation

The preferred way to install this extension is through composer.

Either run

$ php composer.phar require slatiusa/yii2-nestable "dev-master"

or add

"slatiusa/yii2-nestable": "dev-master"

to the require section of your composer.json file.

Usage

Make sure you've attached the NestedSetsBehavior (creocoder/yii2-nested-sets) correctly to your model. Then add the node move handler to you controller by attaching the supplied action;

use slatiusa\nestable\Nestable;

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

And then render the widget in your view;

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,
    ],
]);

You can either supply an ActiveQuery object in query from which a tree will be built. You can also supply an item list;

    ...
    '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],
        ]],
    ],

The modelOptions['name'] should hold an attribute name that will be used to name on the items in the list. You can alternatively supply an unnamed function($model) to build your own content string.

Supply a pluginEvents['change'] with some JavaScript code to catch the change event fired by jquery.nestable plugin. The pluginOptions accepts all the options for the original jquery.nestable plugin.

统计信息

  • 总下载量: 17.86k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 19
  • 点击次数: 1
  • 依赖项目数: 5
  • 推荐数: 0

GitHub 信息

  • Stars: 17
  • Watchers: 5
  • Forks: 11
  • 开发语言: JavaScript

其他信息

  • 授权协议: BSD
  • 更新时间: 2015-04-27