laravel-admin 开发 bootstrap-treeview 扩展包

laravel-admin 扩展开发文档
https://laravel-admin.org/doc...

效果图:

clipboard.png

开发过程:

1、先创建Laravel项目,并集成laravel-admin,教程:

http://note.youdao.com/notesh...

2、生成开发扩展包

php artisan admin:extend csp/cascade --namespace=Csp\Cascade

其中, csp/cascade 是包名, CspCascade 是命名空间,生成的结构如下(删减版):

clipboard.png

3、删除没必要的目录,以及添加CSS、JS资源

clipboard.png

4、修改CascadeServiceProvider
4.1、修改视图的命名空间

if ($views = $extension->views()) {$this->loadViewsFrom($views, 'laravel-admin-cascade');
}

4.2、修改资源发布的位置,这里将资源发布到/public/vendor/laravel-admin-ext/cascade 目录下。

if ($this->app->runningInConsole() && $assets = $extension->assets()) {$this->publishes([$assets => public_path('vendor/laravel-admin-ext/cascade')],'laravel-admin-cascade');
}

4.3、编写视图文件,在views/目录下创建 cascade.blade.php

clipboard.png

<div class="form-group {!! !$errors->has($label) ?: 'has-error' !!}"><label for="{{$id}}" class="col-sm-2 control-label">{{$label}}</label><div class="{{$viewClass['field']}}">@include('admin::form.error')<div id="csp-bootstrap-tree"></div><input type="hidden" name="{{$id}}" id="{{$id}}">@include('admin::form.help-block')</div>
</div>

4.4、编写 CascadeTreeView 继承 Field

<?php
/*** Created by PhpStorm.* User: chenshaoping* Date: 2019/2/10* Time: 10:02*/namespace App\Admin\Extensions\csp\cascade\src;use Encore\Admin\Form\Field;class CascadeTreeView extends Field
{protected $view = 'laravel-admin-cascade::cascade';protected static $css = ['/vendor/laravel-admin-ext/cascade/bootstrap-treeview.min.css'];protected static $js = ['/vendor/laravel-admin-ext/cascade/bootstrap-treeview.min.js'];public function render(){$this->script = <<<EOTvar set = new Set();
var tree = [{text:"Parent 1",id:1,nodes: [{text:"Child 1",id:2,nodes: [{text:"Grandchild 1",id:3,nodes: [{text:"122",id:4,nodes: [{text:"qweqw",id:5,}]}],},{text:"Grandchild 2",id:6,}]},{text:"Child 2",id:7,}]},{text:"Parent 2",id:8,},{text:"Parent 3",id:9,},{text:"Parent 4",id:10,},{text:"Parent 5",id:11,}
]; 
$('#csp-bootstrap-tree').treeview({data: tree, showIcon: false,showCheckbox: true,'showTags':true});
$('#csp-bootstrap-tree').on('nodeChecked', function(event,node) {set.add(node.id);$('#{$this->id}').val(Array.from(set).toString());
});
$('#csp-bootstrap-tree').on('nodeUnchecked', function(event,node) {set.delete(node.id);$('#{$this->id}').val(Array.from(set).toString());
});
EOT;return parent::render();}
}

4.5、在laravel-admin 启动时,添加资源,添加扩展Form

Admin::booting(function () {Admin::js('vendor/laravel-admin-ext/cascade/bootstrap-treeview.min.js');Admin::css('vendor/laravel-admin-ext/cascade/bootstrap-treeview.min.css');Form::extend('cascade', CascadeTreeView::class);
});

5、准备本地安装

5.1、此时如果输入

composer require csp/cascade 

会报以下错误

Could not find a version of package laravel-admin-ext/cascade matching your minimum-stability (stable). Require it with an
explicit version constraint allowing its desired stability.

原因很简单,composer的最小稳定性设置不满足,require 需要的是稳定版本,我们这里的确实 dev的版本;这里有2种解决方式:
1、修改项目的composer.json

"minimum-stability": "dev",
"prefer-stable": true,

2、修改扩展包的composer.json

"version": "1.0.0",

5.2、开始本地安装

composer require csp/cascade

5.3、发布资源

php artisan vendor:publish --provider="Csp\Cascade\CascadeServiceProvider"

此时会看到在 public/vendor/laravel-admin-ext/cascade 目录下面有静态资源。

6、使用

$form->cascade('parent_id','权限')->help('陈少平');

提交表单的时候,会将 parent_id 以 ,(逗号) 分割提交所有被选中的值。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/388315.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

怎么看服务器上jdk安装位置,查看云服务器jdk安装路径

查看云服务器jdk安装路径 内容精选换一换用户可以在公有云MRS集群以外的节点上使用客户端&#xff0c;在使用客户端前需要安装客户端。如果集群外的节点已安装客户端且只需要更新客户端&#xff0c;请使用安装客户端的用户例如root。针对MRS 3.x之前版本的集群&#xff0c;需要…

公司生日会生日礼物_你的生日有多受欢迎?

公司生日会生日礼物In the years before 2020, it was common for a large number of school children (20–30 or more) to physically colocate for their math lessons. And in many a class, students were asked to compute the probability that two of them had the sam…

Django思维导图

转载于:https://www.cnblogs.com/liangying666/p/9744477.html

wp7开发环境搭建

简介 本文通过step by step的模式讲述如何从0开始搭建Window Phone 7开发环境&#xff0c;如果开发简单的Windows Phone 7程序。只是一篇介绍性的文章,但是迈进Windows Phone 7开发之路其实就那么简单,一起来开发Windows Phone 7吧。 Windows 7安装 目前Windows Phone 7开发…

旧金山字体_旧金山建筑业的兴衰。 施工趋势与历史

旧金山字体This series of articles is devoted to the study of the construction activity of the main city of Silicon Valley — San Francisco. Charts and calculations were built with the help of Jupyter Notebook (Kaggle)该系列文章专门研究硅谷主要城市旧金山的建…

gym100825G. Tray Bien(轮廓线DP)

题意:3 * N的格子 有一些点是坏的 用1X1和1X2的砖铺有多少种方法 题解:重新学了下轮廓线 写的很舒服 #include <bits/stdc.h> using namespace std; typedef long long ll;int n, m; int vis[30][5]; ll dp[25][1 << 3];void dfs(int num, int i, int state, int n…

lambda函数,函数符_为什么您永远不应该在Lambda函数中使用print()

lambda函数&#xff0c;函数符两个Lambda用户的故事 (A Tale of Two Lambda Users) 故事1&#xff1a;业余 (Tale #1: The Amateur) One moment everything is fine, then … Bam! Your Lambda function raises an exception, you get alerted and everything changes instantl…

ai 中 统计_AI统计(第2部分)

ai 中 统计Today I plan to cover the following topics: Linear independence, special matrices, and matrix decomposition.今天&#xff0c;我计划涵盖以下主题&#xff1a;线性独立性&#xff0c;特殊矩阵和矩阵分解。 线性独立 (Linear independence) A set of vectors …

twitter数据分析_Twitter上最受欢迎的数据科学文章主题

twitter数据分析If you’ve written data science articles or are trying to get started, finding the most popular topics is a big help in getting your articles read. Below are the steps to easily determine what these topics are using R and the results of the …

JAVA遇见HTML——JSP篇(JSP状态管理)

案例&#xff1a;Cookie在登录中的应用 URL编码与解码的工具类解决中文乱码的问题&#xff0c;这个工具类在java.net.*包里 编码&#xff1a;URLEncoder.encode(String s,String enc)//s&#xff1a;对哪个字符串进行编码&#xff0c;enc&#xff1a;用的字符集&#xff08;例&…

PE文件讲解

我们大家都知道&#xff0c;在Windows 9x、NT、2000下&#xff0c;所有的可执行文件都是基于Microsoft设计的一种新的文件格式Portable Executable File Format&#xff08;可移植的执行体&#xff09;&#xff0c;即PE格式。有一些时候&#xff0c;我们需要对这些可执行文件进…

是什么使波西米亚狂想曲成为杰作-数据科学视角

平均“命中率”是什么样的 (What an Average ‘Hit’ looks like) Before we break the song down, let us have a brief analysis of what the greatest hits of all time had in common. I have picked 1500 songs ( charting hits ) right from the ’50s to the’10s, spre…

流行编程语言_编程语言的流行度排名

流行编程语言There has never been a unanimous agreement on what the most popular programming languages are, and probably never will be. Yet we believe that there is merit in trying to come up with ways to rank the popularity of programming languages. It hel…

使用UIWebView加载网页

1、使用UIWebView加载网页 运行XCode 4.3&#xff0c;新建一个Single View Application&#xff0c;命名为WebViewDemo。 2、加载WebView 在ViewController.h添加WebView成员变量和在ViewController.m添加实现 [cpp] view plaincopyprint?#import <UIKit/UIKit.h> …

corba的兴衰_数据科学薪酬的兴衰

corba的兴衰意见 (Opinion) 目录 (Table of Contents) Introduction 介绍 Salary and Growth 薪资与增长 Summary 摘要 介绍 (Introduction) In the past five years, data science salary cumulative growth has varied between 12% in the United States, according to Glass…

10 个深恶痛绝的 Java 异常。。

异常是 Java 程序中经常遇到的问题&#xff0c;我想每一个 Java 程序员都讨厌异常&#xff0c;一 个异常就是一个 BUG&#xff0c;就要花很多时间来定位异常问题。 什么是异常及异常的分类请看这篇文章&#xff1a;一张图搞清楚 Java 异常机制。今天&#xff0c;栈长来列一下 J…

如何实施成功的数据清理流程

干净的数据是发现和洞察力的基础。 如果数据很脏&#xff0c;您的团队为分析&#xff0c;培养和可视化数据而付出的巨大努力完全是在浪费时间。 当然&#xff0c;肮脏的数据并不是新的。 它早在计算机变得普及之前就困扰着决策。 现在&#xff0c;计算机技术已普及到日常生活中…

通才与专家_那么您准备聘请数据科学家了吗? 通才还是专家?

通才与专家Throughout my 10-year career, I have seen people often spend their time and energy in passionate debates about what data science can deliver, and what data scientists do or do not do. I submit that these are the wrong questions to focus on when y…