多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# 前端hightchart.js分析   openstack里的CPU、硬盘等性能监控图形,是使用hightchart.js这个插件实现的。这里学习是如果将angularjs与hightchart结合在一起。   下面给出一个 angularjs 封装D atepicker 的例子。 Datepicker\scripts\directives\directives.js: ~~~ angular.module('myApp.directives', []) .directive('datepicker', function(){ return { // Enforce the angularJS default of restricting the // directive to attributes only restrict: 'A', // Always use along with an ng-model require : '?ngModel', scope : { // This method needs to be defined and // passed in to the directive from the view controller select : '&' // Bind the select function we refer to // right scope }, link : function(scope, element, attrs, ngModel){ if (!ngModel) return; var optionsObj = {}; optionsObj.dateFormat = 'mm/dd/yy'; // 更新模型数据 var updateModel = function(dateTxt){ scope.$apply(function(){ // Call the internal AngularJS helper to // update the two-way binding ngModel.$setViewValue(dateTxt); }); } optionsObj.onSelect = function(dateTxt, picker){ updateModel(dateTxt); if (scope.select){ scope.$apply(function(){ scope.select({date: dateTxt}); }); } } ngModel.$render = function() { // Use the AngularJS internal 'binding-specific' variable element.datepicker('setDate', ngModel.$viewValue || ''); } element.datepicker(optionsObj); } } }); function test(){ $("#testDatepicker").datepicker({ onselect: function (dateText, inst) {//选中事件 console.log("onselect, dateText", dateText); console.log("onselect, inst", inst); }, beforeShow: function (input) {//日期控件显示面板之前 console.log("beforeShow, input", input); }, onClose: function (dateText, inst) {//当日期面板关闭后触发此事件(无论是否有选择日期) console.log("onClose, dateText", dateText); console.log("onClose, inst", inst); } }); $.datepicker.regional['zh-CN'] = { closeText: '关闭', prevText: '<上月', nextText: '下月>', currentText: '今天', monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'], monthNamesShort: ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'], dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'], dayNamesShort: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'], dayNamesMin: ['日', '一', '二', '三', '四', '五', '六'], dateFormat: 'yy-mm-dd', firstDay: 1, isRTL: false }; $.datepicker.setDefaults($.datepicker.regional['zh-CN']); } ~~~ Datepicker\scripts\controllers\controllers.js: ~~~ var app = angular.module('myApp', ['myApp.directives']); app.controller('MainCtrl', function($scope){ $scope.myText = 'Not Selected'; $scope.currentDate = ''; $scope.updateMyText = function(date){ $scope.myText = 'Selected'; } }); ~~~ Datepicker\index.html ~~~ <!DOCTYPE html> <html lang="en" ng-app="myApp"> <head> <meta charset="UTF-8"> <title>jQuery Datepicker</title> <script src="./scripts/vender/jquery.min.js"></script> <script src="./scripts/vender/jquery-ui.js"></script> <script src="./scripts/vender/angular.js"></script> <link rel="stylesheet" href="./css/jquery-ui.css" > <script src="./scripts/directives/directives.js"></script> <script src="./scripts/controllers/controllers.js"></script> </head> <body ng-controller="MainCtrl"> <input datepicker ng-model="$parent.currentDate" select="updateMyText(date)"><br/> {{myText}}-{{currentDate}} </body> <script type="text/javascript"> </script> </html> ~~~