Giter Club home page Giter Club logo

yii2-wwtree's Introduction

yii2-wwtree

使用方式

安装

composer require wodrow/yii2-wwtree dev-master
模型
public function behaviors()
{
    return [
        'tree' => [
            'class' => \wodrow\yii2wwtree\TreeBehavior::class,
            'primaryKeyAttribute' => 'your_pk_id_filed_name',
            'parentKeyAttribute' => 'your_parent_id_filed_name',
            'nameKeyAttribute' => 'your_name_filed_name',
            'sortKeyAttribute' => 'your_sort_filed_name',
            'iconKeyAttribute' => 'your_icon_filed_name',
            'iconColorKeyAttribute' => 'your_icon_color_filed_name',
        ],
    ];
}
视图
<?=wodrow\yii2wwtree\TreeWidget::widget([
    'treeModelClass' => "your model class",
    // 'custom_field_view' => "@your/extend/view",
    // 'ajaxUrl' => "",
]) ?>

注意

数据表必须要有id, pid(父级), name, sort, icon, icon_color这六个字段,字段名可以是TreeBehavior配置的字段名;
其他字段根据需要自己添加, 在custom_field_view视图里可以处理添加的字段,使用它生成的模型。

如果使用ajaxUrl,推荐在控制器添加actions

public function actions()
{
    return [
        ...,
        'to-your-ajax-url' => [
            'class' => \wodrow\yii2wwtree\SearchAction::class,
            'searchClass' => TestTree::class,
            'idKeyAttr' => 'your id field key',
            'textKeyAttr' => 'your text field key',
        ],
    ];
}

截图

kiEcj0.png

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.