1.  
  2. 1 /** 根据参数定制表格
  3. * api接口:
  4. * form-model:[item1,item2,item3]
  5. * form-properties:[
  6. * {key:'',label:'',thClass:''}, key为item对象的key,label为该key对应的表头,thClass主要用于列少时平分一行
  7. * ...
  8. * ]
  9. * 对应一行后面的编辑,删除,详情按钮
  10. * form-actions:{
  11. * edit/delete/detail:{
  12. * stateUrl:'', 对应点击该按钮后跳转的路由状态
  13. * stateParams:[{
  14. * key:'', 用来拼接ui-router的sref-->({key:object.objectKey}),支持多参数传递。
  15. * objectKey:'',
  16. * }]
  17. * }
  18. * }
  19. *示例
  20. * <by-table tb-models="formModel" tb-properties="formProperties" tb-actions="formAction"></by-table>
  21. *
  22. *
  23. *
  24.  
  25. model用于初始表格数据
  26. $scope.formModel = [
  27. {id:1,name:"张三",sex:'男'},
  28. {id:2,name:"李四",sex:'男'},
  29. {id:3,name:"王五",sex:'男'}
  30. ];
  31.  
  32. thClass 主要用于珊格布局,控制其长度
  33. $scope.formProperties = [
  34. {key:'id',label:'ID'},
  35. {key:'name',label:'姓名','thClass':'col-md-3'},
  36. {key:'sex',label:'性别','thClass':'col-md-3'}
  37. ]
  38.  
  39. 配合而ui-route 完成到增删改查的路由跳转
  40. $scope.formAction = {
  41. //stateParams:
  42. //stateUrl({key:object.objectKey});
  43. //add 不需要stateUrl
  44. detail:{
  45. stateUrl:'person.detail',
  46. stateParams:{
  47. key:'id',
  48. objectKey:'id'
  49. }
  50. },
  51. edit:{
  52. stateUrl:'person.edit'
  53. },
  54. delete:{
  55. stateUrl:'person.delete'
  56. }
  57. }
  58. */
  59.  
  60. angular.module('testApp')
  61. .directive('byTable', function(){
  62. return{
  63. restrict: 'E',
  64. templateUrl:'scripts/components/form/form-template/table.html',
  65. scope:{
  66. tbModels:'=',
  67. tbProperties:'=',
  68. tbActions:'='
  69. },
  70. link:function ($scope,$elem,$attr){
  71. $scope.hasOper = false;
  72. var notNull = function (data){
  73. return !!data;
  74. }
  75.  
  76. //private action info
  77. $scope._tbActions = {
  78. detail:null,
  79. delete:null,
  80. edit:null
  81. }
  82.  
  83. // 必须传递一个数组
  84. //输入[{key1,value1},{key2,value2}],
  85. //输出key1:value1,key2:value2
  86. var getParams = function(datas){
  87. console.log("....");
  88. var arr_len = datas.length;
  89. var res = "";
  90. var i=0;
  91. if(arr_len<=0){
  92. return "";
  93. }
  94.  
  95. res = datas[0].key +":tbModel." + datas[0].objectKey;
  96. if(arr_len>1){
  97. for(i=1;i<arr_len;i++){
  98. res += (","+datas[i].key +":tbModel." + datas[i].objectKey);
  99. }
  100. }
  101. return res;
  102. }
  103.  
  104. //get sref str by config
  105. var getSref = function(dataObj){
  106. var params = "";
  107. var strtmp = "";
  108. if(!dataObj.stateUrl){
  109. return "";
  110. }
  111. if(dataObj.stateParams){
  112. var tmp = getParams(dataObj.stateParams);
  113. params = "({"+ tmp +"})";
  114. }
  115. strtmp = dataObj.stateUrl+ params;
  116. return strtmp;
  117. }
  118.  
  119. //initOperContain:'edit','delete','detail'
  120. var initOper = function(){
  121. if($scope.tbActions.detail){
  122. $scope._tbActions.detail = getSref($scope.tbActions.detail)
  123. }
  124. if($scope.tbActions.edit){
  125. $scope._tbActions.edit = getSref($scope.tbActions.edit)
  126. }
  127. if($scope.tbActions.delete){
  128. $scope._tbActions.delete = getSref($scope.tbActions.delete)
  129. }
  130. console.log($scope._tbActions.detail);
  131. }
  132. initOper();
  133.  
  134. //the oper is show?
  135. if(notNull($scope.tbActions.edit)||notNull($scope.tbActions.delete)||notNull($scope.tbActions.detail)){
  136. $scope.hasOper = true;
  137. }
  138. }
  139. }
  140. })

基于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. smarty语法

    HTML中直接显示数据 <{$data}> foreach循环 <{foreach from=$data item=item key=key}> <li data-ind ...

  2. 【Java】Serializable 接口

     本文为大便一箩筐的原创内容,转载请注明出处,谢谢:http://www.cnblogs.com/dbylk/p/4356840.html 参考资料: http://xiebh.iteye.com/b ...

  3. plsql连接不上oracle

    由于oracle存在64位的,但是目前plsql只有32位.导致登录后报错 -------------------------------------------------------------- ...

  4. struts转换器

    struts转换器:在B/S应用中,将字符串请求参数转换为相应的数据类型,是MVC框架提供的功能,而Struts2是很好的MVC框架实现者,理所当然,提供了类型转换机制. 一.类型转换的意义 对于一个 ...

  5. Could not publish server configuration for Tomcat v6.0 Server at localhost.错误问题解决

    经常在使用tomcat服务器的时候 总会发生一些莫名其妙的错误. 就像下面这个错误: 在配置文件中存在多个/MyWeb的配置,导致不能发布服务. 错误信息: Could not publish ser ...

  6. fastjson缺陷--map转换json时出现$ref的情况

    DisableCircularReferenceDetect来禁止循环引用检测: JSON.toJSONString(..., SerializerFeature.DisableCircularRef ...

  7. Foundations of Qt Development 学习笔记 Part1 Tips1-50

    1. 信号函数调用的时候仅仅会发送出信号,所以不需要执行 ,所以对于信号声明就行,但是不需要进行定义. 2. 只有槽函数可以声明为public,private,或者是protected的,而信号不行. ...

  8. UI-隐藏键盘

    键盘的出现于隐藏(代码实现)================================= 1.通知案例: #import "ViewController.h" #import ...

  9. BAT级别对照表

  10. Nodejs 实用工具集笔记

    前言 工具列表 supervisor 安装 使用 node-inspector 安装 使用 SuperAgent 安装 使用 教程 cheerio 安装 使用 教程 总结 前言 学了Nodejs一天了 ...