发表于: 2016-12-26 02:19:05

1 1586


今天完成的事情:给vps装了个加速器,有效的降低了ping和丢包率;查找了图片上传和翻页功能的教程;复习了下angular关于function、自定义指令、服务的知识;


明天计划的事情:研究透找到的翻页教程,因为没有后端数据,做一个自由设定每页显示条数的翻页功能。


遇到的问题:头有点晕,学习效率很低,主要去看些基础知识,刷了下angularjs1.6的英文文档中关于function的部分。


收获:

            current :当前页码,length:总页码,displayLength:显示长度

  1. var calculateIndexes = function (current, length, displayLength) {  
  2.     var indexes = [];  
  3.     var start = Math.round(current - displayLength / 2);  
  4.     var end = Math.round(current + displayLength / 2);  
  5.     if (start <= 1) {  
  6.         start = 1;  
  7.         end = start + displayLength - 1;  
  8.         if (end >= length - 1) {  
  9.             end = length - 1;  
  10.         }  
  11.     }  
  12.     if (end >= length - 1) {  
  13.         end = length ;  
  14.         start = end - displayLength + 1;  
  15.         if (start <= 1) {  
  16.             start = 1;  
  17.         }  
  18.     }  
  19.     for (var i = start; i <= end; i++) {  
  20.         indexes.push(i);  
  21.     }  
  22.     return indexes;  
  23. };  


file-upload


//注入angularjs 模块和服务

var app = angular.module('appName', ['angularFileUpload']);//创建并添加依赖(upload模块名称)

app.controller('ctrlName',[ '$scope', '$upload', function($scope, $upload) {//$upload是依赖的upload模块的服务名称module.service("$upload",[]);

  //这里可以调用依赖的(upload)模块里提供的方法

    $scope.onFileSelect = function($files) {    //$files:是已选文件的名称、大小和类型的数组

        for (var i = 0; i < $files.length; i++) {      

            var file = $files[i];

            console.log(file);

            /*文件上传函数*/

            $scope.upload = $upload.upload({

                url: 'server/upload/url', //上传的url

                //method: 'POST' or 'PUT',

                //headers: {'header-key': 'header-value'},

                //withCredentials: true,

                data: {myObj: $scope.myModelObj},

                file: file, // or list of files ($files) for html5 only

                //fileName: 'doc.jpg' or ['1.jpg', '2.jpg', ...] // to modify the name of the file(s)

                // customize file formData name ('Content-Disposition'), server side file variable name. 

                //fileFormDataName: myFile, //or a list of names for multiple files (html5). Default is 'file' 

                // customize how data is added to formData. See #40#issuecomment-28612000 for sample code

                //formDataAppender: function(formData, key, val){}

            }).progress(function(evt) {//上传进度

            

                console.log('percent: ' + parseInt(100.0 * evt.loaded / evt.total));

                

            }).success(function(data, status, headers, config) {

                // 文件上传成功处理函数

                console.log(data);

                

            }).error(function(data, status, headers, config) {

                //失败处理函数

                console.log('上传失败');

            });

        };

    };

}]);



返回列表 返回列表
评论

    分享到