发表于: 2017-07-26 23:40:53

1 706


一、今天完成的事:

1.学习forEach的用法;

2.优化代码;

二、明天的计划:

1.整理优化页面;

三、遇到的问题:

1.清空函数,大佬查看发现清空设置太蠢,直接用forEach遍历后,将对象中的值都赋值为空即可;

2.判断用户点击的编辑还是新增,原来用的ng-show,大佬查看后可以更改为三元运算符即可;

四、收获:

1、forEach的用法;虽然还不是太懂;

var objs =[{a:1},{a:2}];
angular.forEach(objs, function(data,index,array){
//data等价于array[index]
console.log(data.a+'='+array[index].a);
});

objs:需要遍历的集合

data:遍历时当前的数据

index:遍历时当前索引

array:需要遍历的集合,每次遍历时都会把objs原样的传一次。

也可以不用写后面两个参数:


2、在任务中的用法:

$scope.reset = function () {
//清空时将所有的input框赋值为空即可;
   console.log($scope.params);
   angular.forEach($scope.params,function (data,index) {
$scope.params[index] = '';
   });
   console.log($scope.params)
// $scope.params = {type:"", status: "", page: "", startAt: "", endAt: "",total: ""};
   $state.go('home.Article',$scope.params,{reload:true});

3、简化判断新增还是编辑的方法:

<div class="article-head">
  <strong>{{id ? "编辑列表":"新增列表"}}</strong>
</div>

该运算符的含义是id为真的时候,显示编辑列表,为假时显示新增列表;

在controller,将id提取即可;

// 判断是否有id,来显示“编辑”还是“新增”
$scope.id = $stateParams.id;



返回列表 返回列表
评论

    分享到