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风格的表格生成指令的更多相关文章

  1. [转]AngularJS+UI Router(1) 多步表单

    本文转自:https://www.zybuluo.com/dreamapplehappy/note/54448 多步表单的实现   在线demo演示地址https://rawgit.com/dream ...

  2. angularJS ui router 多视图单独刷新问题

    场景:视图层级如下 view1 --view11 --view111 需求:view11的一个动作过后,单独刷新view12 解决方式:修改层级设计 view1 --view11 --view111 ...

  3. Angularjs ui router,路由嵌套 父controller执行问题

    解决方式来源:https://stackoverflow.com/questions/25316591/angularjs-ui-router-state-reload-child-state-onl ...

  4. 【Bootstrap】 bootstrap-table表格组件

    [Bootstrap-table] 顾名思义,这个组件专注于bootstrap风格的表格的设计,并且提供了很多表格的基础和进阶的功能,给我们开发前端的表格省下很多力气. 本文主要参考这位博主的系列文章 ...

  5. AngularJS 使用 UI Router 实现表单向导

    Today we will be using AngularJS and the great UI Router and the Angular ngAnimate module to create ...

  6. [转]AngularJS 使用 UI Router 实现表单向导

    本文转自:http://www.oschina.net/translate/angularjs-multi-step-form-using-ui-router 今天我们将使用AngularJs和伟大的 ...

  7. Blazor组件提交全记录: FullScreen 全屏按钮/全屏服务 (BootstrapBlazor - Bootstrap 风格的 Blazor UI 组件库)

    Blazor 简介 Blazor 是一个使用 .NET 生成的交互式客户端 Web UI 的框架.和前端同学所熟知的 Vue.React.Angular 有巨大差异. 其最大的特色是使用 C# 代码( ...

  8. 自己写的基于bootstrap风格的弹框插件

    自己写的一款基于bootstrap风格的弹框插件,暂时只有确认框.提示框.后续功能扩展.bug修改再更新. ;(function($){ //默认参数 var PARAMS; var DEFAULTP ...

  9. bootstrap基础学习小记(二)排版、列表、代码风格、表格

    排版——标题.副标题.段落(正文文本).强调内容.粗体.斜体.强调相关的类.文本对齐 <!DOCTYPE HTML> <html> <head> <meta ...

随机推荐

  1. phalcon: 独立的映射,字段名名别名

    class ProductsController extends \Phalcon\Mvc\Controller { public function saveAction() { //Obtain t ...

  2. APP埋点:页面统计与事件统计该如何入手?

    我们平时所说的埋点,可以大致分为两部分,一部分是统计APP页面访问情况,即页面统计:另外一部分是统计APP内的操作行为,及自定义事件统计. 一.页面统计 页面统计,可以统计应用内各个页面的访问次数(P ...

  3. node-wechat 微信推送消息

    https://github.com/nswbmw/node-wechat/blob/master/index.js

  4. LeetCode OJ:Recover Binary Search Tree(恢复二叉搜索树)

    Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing ...

  5. 绕过SQL限制的方法

    突然想我们是否可以用什么方法绕过SQL注入的限制呢?到网上考察了一下,提到的方法大多都是针对AND与“’”号和“=”号过滤的突破,虽然有点进步的地方,但还是有一些关键字没有绕过,由于我不常入侵网站所以 ...

  6. [leetcode]_根据二叉树的先序遍历(后序遍历) + 中序遍历 重建二叉树

    题目1:Construct Binary Tree from Preorder and Inorder Traversal 给定一棵二叉树的先序遍历和中序遍历,求重建二叉树. 思路: 1.先序遍历的第 ...

  7. margin和padding理解

    W3C组织建议把所有网页上的对像都放 在一个盒(box)中,设计师可以通过创建定义来控制这个盒的属性,这些对像包括段落.列表.标题.图片以及层. 盒模型主要定义四个区域:内容 (content).边框 ...

  8. 1.1对java web开发的一点理解

    前言 Q:通常行内人士见面会问你,你做哪方面开发的? A:java web开发的 那么,什么是java web开发? java web开发通常是指java web应用程序的开发.一个B/S架构的 we ...

  9. 什么是镜头shading

    shading分为两种: Lens Shading:由于Lens的光学特性,Sensor影像区的边缘区域接收的光强比中心小,所造成的中心和四角亮度不一致的现象. color shading:由于LEN ...

  10. .Net Remoting编程 ---- 系列文章

    .Net Remoting(应用程序域) - Part.1 摘要: 本文是.Net Remoting系列的第一篇文章,讲述了Remoting的“前驱知识点”--应用程序域.传值封送(Marshal b ...