发表于: 2017-07-19 23:10:21
1 944
今天完成的事情:做了拖动排序的demo,用请求的本地json格式渲染列表。
明天计划的事情:做完公司页面$http请求。
遇到的问题:没有后台数据,自己写数据,自己请求,翻页实现不了,但是其他都问题不大。
收获:angular.foreach 循环方法使用指南
angular有自己的生命周期。循环给一个 angular监听的变量复值时。最好还是用angular自带的循环方法。“angular.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原样的传一次。
也可以不用写后面两个参数:
使用angular-ui-sortable实现可拖拽排序列表
项目需求,添加列表可拖拽排序功能,谷歌了一下,找到一个Angular的插件:angular-ui-sortable,项目地址:https://github.com/angular-ui/ui-sortable
需要在之前引入jQuery,和jquery-ui,否则无法使用。
我们要做的事情,加载数据,拖拽排序并输出当前顺序:
$scope.cannotSort=false;
$scope.sortableOptions={
update:function(e,ui){
console.log("update");
$timeout(function(){
var resArr=[];
for(var i=0;i<$scope.companyLists.length;i++){
resArr.push($scope.companyLists[i].order)
}
console.log(resArr)
})
},stop:function(e,ui){
//do nothing
}
}
//
<tbody ui-sortable="sortableOptions" ng-model="companyLists">
<tr ng-repeat="x in companyLists">
<td ng-bind="x.order">test</td>
<td ng-bind="x.name">test</td>
<td ng-bind="x.industry">test</td>
<td ng-bind="x.province">test</td>
<td ng-bind="x.financing">test</td>
<td ng-bind="x.approvedStatus">test</td>
<td ng-bind="x.freezedStatus">test</td>
<td>test</td>
</tr>
</tbody>
评论