yii2-ztree
The zTree extension for the Yii framework 2.0, (*1)
Installation
The preferred way to install this extension is through composer., (*2)
Either run, (*3)
``` bash
php composer.phar require --prefer-dist liyuze/yii2-ztree "*", (*4)
or add
``` bash
"liyuze/yii2-ztree": "*"
to the require section of your composer.json
file., (*5)
Usage
Once the extension is installed, simply use it in your code by :, (*6)
``` php
= \liyuze\ztree\ZTree::widget([
'setting' => '{
data: {
simpleData: {
enable: true
}
}
}',
'nodes' => '[
{ id:1, pId:0, name:"็ถ่็น1 - ๅฑๅผ", open:true},
{ id:11, pId:1, name:"็ถ่็น11 - ๆๅ "},
{ id:111, pId:11, name:"ๅถๅญ่็น111"},
{ id:112, pId:11, name:"ๅถๅญ่็น112"},
{ id:113, pId:11, name:"ๅถๅญ่็น113"},
{ id:114, pId:11, name:"ๅถๅญ่็น114"},
{ id:12, pId:1, name:"็ถ่็น12 - ๆๅ "},
{ id:121, pId:12, name:"ๅถๅญ่็น121"},
{ id:122, pId:12, name:"ๅถๅญ่็น122"},
{ id:123, pId:12, name:"ๅถๅญ่็น123"},
{ id:124, pId:12, name:"ๅถๅญ่็น124"},
{ id:13, pId:1, name:"็ถ่็น13 - ๆฒกๆๅญ่็น", isParent:true}
]'
]);
?>, (*7)
or, standard use it on your code by:
``` php
= \liyuze\ztree\ZTree::widget([
'id' => 'category_tree', //่ชๅฎไนid
'setting' => '{
view: {
dblClickExpand: false,
showLine: false
},
callback: {
onClick: onClick
}
}',
'nodes' => '[
{ name:"็ถ่็น1 - ๅฑๅผ", open:true,
children: [
{ name:"็ถ่็น11 - ๆๅ ",
children: [
{ name:"ๅถๅญ่็น111"},
{ name:"ๅถๅญ่็น112"},
{ name:"ๅถๅญ่็น113"},
{ name:"ๅถๅญ่็น114"}
]},
{ name:"็ถ่็น12 - ๆๅ ",
children: [
{ name:"ๅถๅญ่็น121"},
{ name:"ๅถๅญ่็น122"},
{ name:"ๅถๅญ่็น123"},
{ name:"ๅถๅญ่็น124"}
]},
{ name:"็ถ่็น13 - ๆฒกๆๅญ่็น", isParent:true}
]
}
]'
]);
?>
Extend
zTree GitHub
zTree API
zTree Demo, (*8)