微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Angularjs编写KindEditor,UEidtor,jQuery指令

  目前angularJS非常火热,本人也在项目中逐渐使用该技术,在angularJS中,指令可以说是当中非常重要的一部分,这里分享一些自己编写的指令:

  注:本人项目中用了oclazyload进行部分JS文件加载

  1、KindEditor

代码如下:
cope,element,attrs,ctrl) { uiLoad.load('../Areas/AdminManage/Content/vendor/jquery/kindeditor/kindeditor-all.js').then(function () { var _initContent,editor; var fexUE = { initEditor: function () { editor = KindEditor.create(element[0],{ width: '100%', height: '400px', resizeType: 1, uploadJson: '/Upload/Upload_Ajax.ashx', formatUploadUrl: false, allowFileManager: true, afterChange: function () { ctrl.$setViewValue(this.html()); } }); }, setContent: function (content) { if (editor) { editor.html(content); } } } if (!ctrl) { return; } _initContent = ctrl.$viewValue; ctrl.$render = function () { _initContent = ctrl.$isEmpty(ctrl.$viewValue) ? '' : ctrl.$viewValue; fexUE.setContent(_initContent); }; fexUE.initEditor(); }); } } }]);

  2、UEditor:

代码如下:
vendor/jquery/ueditor/ueditor.config.js', '../Areas/AdminManage/Content/vendor/jquery/ueditor/ueditor.all.js']).then(function () { var _self = this, _initContent, editor, editorReady = false var fexUE = { initEditor: function () { var _self = this; if (typeof UE != 'undefined') { editor = new UE.ui.Editor({ initialContent: _initContent, autoHeightEnabled: false, autoFloatEnabled: false }); editor.render(element[0]); editor.ready(function () { editorReady = true; _self.setContent(_initContent); editor.addListener('contentChange',function () { scope.$apply(function () { ctrl.$setViewValue(editor.getContent()); }); }); }); } }, setContent: function (content) { if (editor && editorReady) { editor.setContent(content); } } }; if (!ctrl) { return; } _initContent = ctrl.$viewValue; ctrl.$render = function () { _initContent = ctrl.$isEmpty(ctrl.$viewValue) ? '' : ctrl.$viewValue; fexUE.setContent(_initContent); }; fexUE.initEditor(); }); } }; }]);

  3、jquery.Datatable:

代码如下:
0) { for (var i = 0; i < chooseData.length; i++) { listID += chooseData[i].value + ","; } } return listID.substring(0,listID.length - 1); } $scope.refreshTable = function () { $scope.dataTable.fnClearTable(0); //清空数据 $scope.dataTable.fnDraw(); //重新加载数据 } uiLoad.load(['../Areas/AdminManage/Content/vendor/jquery/datatables/jquery.dataTables.min.js', '../Areas/AdminManage/Content/vendor/jquery/datatables/dataTables.bootstrap.js', '../Areas/AdminManage/Content/vendor/jquery/datatables/dataTables.bootstrap.css']).then(function () { var options = {}; if ($scope.dtOptions) { angular.extend(options,$scope.dtOptions); } options["processing"] = false; options["info"] = false; options["serverSide"] = true; options["language"] = { "processing": '正在加载...', "lengthMenu": "每页显示 _MENU_ 条记录数", "zeroRecords": '
', "info": "当前显示第 _PAGE_ 页 共 _PAGES_ 页", "infoEmpty": "空", "infoFiltered": "搜索到 _MAX_ 条记录", "search": "搜索", "paginate": { "first": "首页", "prevIoUs": "上一页", "next": "下一页", "last": "末页" } } options["fnRowCallback"] = function (nRow,aData,idisplayIndex,idisplayIndexFull) { $compile(nRow)($scope); } $scope.dataTable = $element.dataTable(options); }); $element.find("thead th").each(function () { $(this).on("click","input:checkBox",function () { var that = this; $(this).closest('table').find('tr > td:first-child input:checkBox').each(function () { this.checked = that.checked; $(this).closest('tr').toggleClass('selected'); }); }); }) } }]);

以上3则就是本人编写的AngularJS指令,这里抛砖引玉下,希望对小伙伴们能有所帮助,

原文地址:https://www.jb51.cc/jquery/56073.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐