kasoft/yii2-jstree
最新稳定版本:v1.0.16
Composer 安装命令:
composer require kasoft/yii2-jstree
包简介
jsTree is jquery plugin, that provides interactive trees
关键字:
README 文档
README
jsTree for Yii2 is a Extension to display an handle ActiveRecord Models with jsTree.
- load tree data with ajax and display tree
- define icons for different tree items (e.g. with FontAwesome)
- context menu with update, rename and delete
- move tree items by drag'n'drop
- context submenu with individual node types
- dynamic context menu where items for special types can be removed
- individual text and context menu messages
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist kasoft/yii2-jstree "1.0.14"
or add
"kasoft/yii2-jstree": "1.0.14",
to the require section of your composer.json file.
Latest News
Version 1.0.16
- Removed unnecessary Bootstrap Dependency
Version 1.0.14
- Define a id wich node via initialOpenId wich will open after load
Version 1.0.13
- Individuall "New node" Text can be set in standardMsg
Version 1.0.12
- Fixed missing Icon for Duplicate
Version 1.0.11
- New: Duplicate Items in Kontext Menu with Model Duplication
- Yii2 Error Messages while create or duplicate are transportet to Javascript Alert
- Remove Contextmenu Items for special Types (e.g. No "delete" for type "page")
Version 1.0.10
- Fixed array_merge error
Version 1.0.9
- More Text that could be translated
- Fixed rename error
Version 1.0.8
- Set individual Context Menu Text and individual Alert Messages
- Choose which Context Menu should be displayed (create, edit, delete, rename)
- Set individual Icon for each Enty
- Setup a create Submenu with different new node Types and define these Node Type as described in JsTree Docs with different possibilities (allow childs, allow move, set icon)
Version 1.0.7
- Added modelPropertyType with default value + online/offline glyphicons as default
Version 1.0.6
- Fixed a Problem with Yii 2.0.14, because of a diffrent Error Handling, the Tree wasn't displayes
- REQUEST check in Controller isn't needed any more
Version 1.0.5
- Selecting a Node will trigger update action via Ajax and load result in .jstree-result div. If the .jstree-result is not found, it will redirect to Update Action
- Changed all Submenu Icons to Glyhicon
Version 1.0.4
- Updated Composer Settings
Version 1.0.3
- Selected multiple Nodes are all deleted
Usage without Model (JSON only)
The simple Version just displays the tree with a provided json url. You have to provide the json data by an url
$tree = new \kasoft\jstree\JsTree([ 'jsonUrl' => '/my_jsonurl/data/whatever', ]);
<div id="jstree"></div>
Usage with Yii2 Model
If you want to use the Extension so Display the Tree from your Data, do Operations like move, create, delete, rename and open the form view by Click use this Version.
Before you start, check your Database or your Model! Do you have all required Fields?
Together with a Database (tested with MySQL) and a set of Fields to order and structure the tree are needed. The Tree is displayed in a DIV. The Extensions handels create, move, rename and delete for you. A click on a Tree Item will dipslay the form to edith data in another div.
See the Test Setup in the "demo" Folder!
Set up you Database with the needed fileds (can have different names) *name Name or Titel to Display in in the tree (required) *parent_id Id for nesting the tree (required) *position For sorting the tree items (required) *type Type of the Item, used for Icon and rights (optional)
Set up your Model with these Fields. Important: Only the name is allwoed to be a required Field! Otherwise the Contextmenue "New" will probably not work.
Add this to your Controller. All Items with (*) are required!
<? public function actionIndex() { $tree = new \kasoft\jstree\JsTree([ 'modelName'=>'backend\models\MY_MODEL_NAME', // * Namespace of the Model 'modelPropertyId' => 'id' // * primary Key 'modelPropertyParentId' => 'parentId', // * Parent ID for tree items 'modelPropertyPosition' => 'position', // *for sorting items 'modelPropertyName' => 'name', // * Fieldname to show 'modelFirstParentId' => NULL, // * ID for the Tree to start 'modelPropertyType' => 'type', // Item type (for Icon and jsTree rights) 'controllerId' => 'index', // Controler Actions which should handle everything 'jstreeDiv' => '#jstree', // DIV where the Tree will be displayed 'jstreeIcons' => false, // Show Icons or not 'jstreePlugins' => ["contextmenu", "dnd",..], // Plugins to be load 'jstreeContextMenue' => [ // Define individual menu "remove" => [ "text" => "Delete", "icon" => "glyphicon glyphicon-plane", ], "edit" => [ "text" => "Edit", "icon" => "glyphicon glyphicon-picture", ], "create" => [ "text" => "Create new", "icon" => "glyphicon glyphicon-barcode", "type"=> "online", "submenu" => [ //Define submenu for creating node types ["text"=>"Create new with Type offline","icon" => "glyphicon glyphicon-barcode","type"=>"offline"], ["text"=>"Create new with Type online","icon" => "glyphicon glyphicon-plane", "type"=>"online"], ["text"=>"Create new with Type default","glyphicon glyphicon-volume-up","type"=>""], ] ], "rename" => [ "text" => "Rename", "icon" => "glyphicon glyphicon-volume-up", ], ], 'jstreeType' => [ // jsTree Type Options "#" => [ "max_children" => -1, "max_depth" => -1, "valid_children" => -1, "icon" => "glyphicon glyphicon-th-list" ], "default" => [ "icon" => "glyphicon glyphicon-question-sign" ], ], 'jstreeMsg' => [ // Individual Alert Messages "confirmdelete" => "Are you sure? Delete?", "nothere" => "Not possible at this Position!", ] ]); return $this->render('index'); } ?>
Put this in the index view file. A Click on an Item will delegate the update action to the result field. Also the form should have a class named "jstree-form" to delegate the result of the form submit to the div.
<div id="jstree"></div> <div class="result"></div>
kasoft/yii2-jstree 适用场景与选型建议
kasoft/yii2-jstree 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 52.93k 次下载、GitHub Stars 达 4, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「extension」 「yii2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kasoft/yii2-jstree 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kasoft/yii2-jstree 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kasoft/yii2-jstree 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A custom URL rule class for Yii 2 which allows to create translated URL rules
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
TYPO3 CMS extension to create gallery content element with preset crop ratios and pagination
UI Kit 3 Extension for Yii2
Adds more BBCode
Define your own css rule-sets for the TYPO3 CMS backend.
统计信息
- 总下载量: 52.93k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 未知