基于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 ...
随机推荐
- time模块详解
本文转自这里: 在Python中,与时间处理有关的模块就包括:time,datetime以及calendar.这篇文章,主要讲解time模块. 在开始之前,首先要说明这几点: 在Python中,通常有 ...
- 升级openssl 到 1.0.1s 最新版
1.下载 wget http://www.openssl.org/source/openssl-1.0.1s.tar.gz 2.解压 tar -zxf openssl-1.0.1s.tar.gz cd ...
- 【poj2155】Matrix(二维树状数组区间更新+单点查询)
Description Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the ...
- 【Wannafly挑战赛9-B】数一数
链接:https://www.nowcoder.net/acm/contest/71/B 题目就不贴了.. 设res[i]为第i行的最终结果,可以想到,res[i]为0或不为0.长度不是最短的字符串r ...
- Flask的简单认识
Flask的简单认识 Flask是轻量级的框架,适用于简单的程序 与Django的比较: Django: 无socket,中间件,路由,视图(CBV,FBV),模板,ORM, cookie,sessi ...
- 视图框架:Spring MVC 4.0(1)
目录 一.表单标签库 1.1.简介 1.2.常用属性 1.3.form标签与input标签 1.4.checkbox标签 1.5.radiobutton标签 1.6.password标签 1.7.se ...
- [置顶]
【机器学习PAI实践三】雾霾成因分析
一.背景 如果要人们评选当今最受关注话题的top10榜单,雾霾一定能够入选.如今走在北京街头,随处可见带着厚厚口罩的人在埋头前行,雾霾天气不光影响了人们的出行和娱乐,对于人们的健康也有很大危害.本文通 ...
- 用php实现四种常见的排序算法
几种常见的排序 排序是一个程序员的基本功,对于初级phper,更是可以通过排序算法来锻炼自己的思维能力. 所谓排序,就是对一组数据,按照某个顺序排列的过程.下面就总结四种常用的php排序算法,分别是冒 ...
- Linux命令学习笔记目录
Linux命令学习笔记目录 最近正在使用,linux,顺便将用到的命令整理了一下. 一. 文件目录操作命令: 0.linux命令学习笔记(0):man 命令 1.linux命令学习笔记(1):ls命令 ...
- 【retina】手机上 1PX 边框
1像素边框,在2倍屏幕上为2“占位”,3倍屏上为3“占位”,但设计师就要1“占位” .content h1:after, .content h2:after { border-top: 1px sol ...
1 /** 根据参数定制表格