基于angularJs+ui-router+bootstrap风格的表格生成指令
- 1 /** 根据参数定制表格
- * api接口:
- * form-model:[item1,item2,item3]
- * form-properties:[
- * {key:'',label:'',thClass:''}, key为item对象的key,label为该key对应的表头,thClass主要用于列少时平分一行
- * ...
- * ]
- * 对应一行后面的编辑,删除,详情按钮
- * form-actions:{
- * edit/delete/detail:{
- * stateUrl:'', 对应点击该按钮后跳转的路由状态
- * stateParams:[{
- * key:'', 用来拼接ui-router的sref-->({key:object.objectKey}),支持多参数传递。
- * objectKey:'',
- * }]
- * }
- * }
- *示例
- * <by-table tb-models="formModel" tb-properties="formProperties" tb-actions="formAction"></by-table>
- *
- *
- *
- model用于初始表格数据
- $scope.formModel = [
- {id:1,name:"张三",sex:'男'},
- {id:2,name:"李四",sex:'男'},
- {id:3,name:"王五",sex:'男'}
- ];
- thClass 主要用于珊格布局,控制其长度
- $scope.formProperties = [
- {key:'id',label:'ID'},
- {key:'name',label:'姓名','thClass':'col-md-3'},
- {key:'sex',label:'性别','thClass':'col-md-3'}
- ]
- 配合而ui-route 完成到增删改查的路由跳转
- $scope.formAction = {
- //stateParams:
- //stateUrl({key:object.objectKey});
- //add 不需要stateUrl
- detail:{
- stateUrl:'person.detail',
- stateParams:{
- key:'id',
- objectKey:'id'
- }
- },
- edit:{
- stateUrl:'person.edit'
- },
- delete:{
- stateUrl:'person.delete'
- }
- }
- */
- angular.module('testApp')
- .directive('byTable', function(){
- return{
- restrict: 'E',
- templateUrl:'scripts/components/form/form-template/table.html',
- scope:{
- tbModels:'=',
- tbProperties:'=',
- tbActions:'='
- },
- link:function ($scope,$elem,$attr){
- $scope.hasOper = false;
- var notNull = function (data){
- return !!data;
- }
- //private action info
- $scope._tbActions = {
- detail:null,
- delete:null,
- edit:null
- }
- // 必须传递一个数组
- //输入[{key1,value1},{key2,value2}],
- //输出key1:value1,key2:value2
- var getParams = function(datas){
- console.log("....");
- var arr_len = datas.length;
- var res = "";
- var i=0;
- if(arr_len<=0){
- return "";
- }
- res = datas[0].key +":tbModel." + datas[0].objectKey;
- if(arr_len>1){
- for(i=1;i<arr_len;i++){
- res += (","+datas[i].key +":tbModel." + datas[i].objectKey);
- }
- }
- return res;
- }
- //get sref str by config
- var getSref = function(dataObj){
- var params = "";
- var strtmp = "";
- if(!dataObj.stateUrl){
- return "";
- }
- if(dataObj.stateParams){
- var tmp = getParams(dataObj.stateParams);
- params = "({"+ tmp +"})";
- }
- strtmp = dataObj.stateUrl+ params;
- return strtmp;
- }
- //initOperContain:'edit','delete','detail'
- var initOper = function(){
- if($scope.tbActions.detail){
- $scope._tbActions.detail = getSref($scope.tbActions.detail)
- }
- if($scope.tbActions.edit){
- $scope._tbActions.edit = getSref($scope.tbActions.edit)
- }
- if($scope.tbActions.delete){
- $scope._tbActions.delete = getSref($scope.tbActions.delete)
- }
- console.log($scope._tbActions.detail);
- }
- initOper();
- //the oper is show?
- if(notNull($scope.tbActions.edit)||notNull($scope.tbActions.delete)||notNull($scope.tbActions.detail)){
- $scope.hasOper = true;
- }
- }
- }
- })
基于angularJs+ui-router+bootstrap风格的表格生成指令的更多相关文章
- [转]AngularJS+UI Router(1) 多步表单
本文转自:https://www.zybuluo.com/dreamapplehappy/note/54448 多步表单的实现 在线demo演示地址https://rawgit.com/dream ...
- angularJS ui router 多视图单独刷新问题
场景:视图层级如下 view1 --view11 --view111 需求:view11的一个动作过后,单独刷新view12 解决方式:修改层级设计 view1 --view11 --view111 ...
- Angularjs ui router,路由嵌套 父controller执行问题
解决方式来源:https://stackoverflow.com/questions/25316591/angularjs-ui-router-state-reload-child-state-onl ...
- 【Bootstrap】 bootstrap-table表格组件
[Bootstrap-table] 顾名思义,这个组件专注于bootstrap风格的表格的设计,并且提供了很多表格的基础和进阶的功能,给我们开发前端的表格省下很多力气. 本文主要参考这位博主的系列文章 ...
- AngularJS 使用 UI Router 实现表单向导
Today we will be using AngularJS and the great UI Router and the Angular ngAnimate module to create ...
- [转]AngularJS 使用 UI Router 实现表单向导
本文转自:http://www.oschina.net/translate/angularjs-multi-step-form-using-ui-router 今天我们将使用AngularJs和伟大的 ...
- Blazor组件提交全记录: FullScreen 全屏按钮/全屏服务 (BootstrapBlazor - Bootstrap 风格的 Blazor UI 组件库)
Blazor 简介 Blazor 是一个使用 .NET 生成的交互式客户端 Web UI 的框架.和前端同学所熟知的 Vue.React.Angular 有巨大差异. 其最大的特色是使用 C# 代码( ...
- 自己写的基于bootstrap风格的弹框插件
自己写的一款基于bootstrap风格的弹框插件,暂时只有确认框.提示框.后续功能扩展.bug修改再更新. ;(function($){ //默认参数 var PARAMS; var DEFAULTP ...
- bootstrap基础学习小记(二)排版、列表、代码风格、表格
排版——标题.副标题.段落(正文文本).强调内容.粗体.斜体.强调相关的类.文本对齐 <!DOCTYPE HTML> <html> <head> <meta ...
随机推荐
- smarty语法
HTML中直接显示数据 <{$data}> foreach循环 <{foreach from=$data item=item key=key}> <li data-ind ...
- 【Java】Serializable 接口
本文为大便一箩筐的原创内容,转载请注明出处,谢谢:http://www.cnblogs.com/dbylk/p/4356840.html 参考资料: http://xiebh.iteye.com/b ...
- plsql连接不上oracle
由于oracle存在64位的,但是目前plsql只有32位.导致登录后报错 -------------------------------------------------------------- ...
- struts转换器
struts转换器:在B/S应用中,将字符串请求参数转换为相应的数据类型,是MVC框架提供的功能,而Struts2是很好的MVC框架实现者,理所当然,提供了类型转换机制. 一.类型转换的意义 对于一个 ...
- Could not publish server configuration for Tomcat v6.0 Server at localhost.错误问题解决
经常在使用tomcat服务器的时候 总会发生一些莫名其妙的错误. 就像下面这个错误: 在配置文件中存在多个/MyWeb的配置,导致不能发布服务. 错误信息: Could not publish ser ...
- fastjson缺陷--map转换json时出现$ref的情况
DisableCircularReferenceDetect来禁止循环引用检测: JSON.toJSONString(..., SerializerFeature.DisableCircularRef ...
- Foundations of Qt Development 学习笔记 Part1 Tips1-50
1. 信号函数调用的时候仅仅会发送出信号,所以不需要执行 ,所以对于信号声明就行,但是不需要进行定义. 2. 只有槽函数可以声明为public,private,或者是protected的,而信号不行. ...
- UI-隐藏键盘
键盘的出现于隐藏(代码实现)================================= 1.通知案例: #import "ViewController.h" #import ...
- BAT级别对照表
- Nodejs 实用工具集笔记
前言 工具列表 supervisor 安装 使用 node-inspector 安装 使用 SuperAgent 安装 使用 教程 cheerio 安装 使用 教程 总结 前言 学了Nodejs一天了 ...