controllerjump.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'example/controllerjump/index',
  8. add_url: '',
  9. edit_url: '',
  10. del_url: 'example/controllerjump/del',
  11. multi_url: '',
  12. }
  13. });
  14. var table = $("#table");
  15. // 初始化表格
  16. table.bootstrapTable({
  17. url: $.fn.bootstrapTable.defaults.extend.index_url,
  18. columns: [
  19. [
  20. {field: 'state', checkbox: true, },
  21. {field: 'id', title: 'ID'},
  22. {field: 'admin_id', title: __('Admin_id')},
  23. {field: 'title', title: __('Title')},
  24. {field: 'ip', title: __('IP'), formatter: Controller.api.formatter.ip},
  25. {field: 'createtime', title: __('Create time'), formatter: Table.api.formatter.datetime},
  26. {field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: function (value, row, index) {
  27. return Table.api.formatter.operate(value, row, index, table);
  28. }
  29. }
  30. ]
  31. ]
  32. });
  33. // 为表格绑定事件
  34. Table.api.bindevent(table);
  35. },
  36. add: function () {
  37. Form.api.bindevent($("form[role=form]"));
  38. },
  39. edit: function () {
  40. Form.api.bindevent($("form[role=form]"));
  41. },
  42. api: {
  43. formatter: {
  44. ip: function (value, row, index) {
  45. //这里手动构造URL
  46. url = "example/bootstraptable?" + this.field + "=" + value;
  47. //方式一,直接返回class带有addtabsit的链接,这可以方便自定义显示内容
  48. return '<a href="' + url + '" class="label label-success addtabsit" title="' + __("Search %s", value) + '">' + __('Search %s', value) + '</a>';
  49. //方式二,直接调用Table.api.formatter.addtabs
  50. return Table.api.formatter.addtabs(value, row, index, url);
  51. }
  52. }
  53. }
  54. };
  55. return Controller;
  56. });