angular.copy下的ng-repeat失效问题,求解决

mingqingyuefeng 2017-09-24 04:31:29
打算做一下,固定表头,大体思路是,在table中,ng-repeat 声称数据后,复制table表,调整z-index,最终达到固定表头的效果。
现在的问题,复制后的表格,数据从后台拿不到,ng-repeat没有起作用。具体代码:

<div class="first-frame" id="flag">
<table>
<thead>
<th>姓名</th>
<th>性别</th>
<th>年龄</th>
</thead>
<tbody>
<tr ng-repeat="data in testData track by $index" repeat-finish="renderFinish()">
<td>{{data.name}}</td>
<td>{{data.gender}}</td>
<td>{{data.age}}</td>
</tr>
</tbody>
</table>
</div>

js代码:

var app=angular.module('myModule',[]);
app.controller('firstController',function($scope){
$scope.testData=[
{
name:"zhangSan",
gender:"man",
age:"29"
},
{
name:"liSi",
gender:"man",
age:"29"
},
{
name:"wangWu",
gender:"man",
age:"29"
},
{
name:"maliu",
gender:"man",
age:"29"
},
];
$scope.renderFinish = function() {
var test = angular.element("#flag");
var testCopy = angular.copy(test);
angular.element("#flag").after(testCopy);
testCopy.addClass('second-frame');
}

});
app.directive('repeatFinish',function(myData){
return {
link: function(scope,element,attr){
console.log(scope.$index)
if(scope.$last == true){
console.log('ng-repeat执行完毕')
scope.$eval( attr.repeatFinish );

}
}
}
})

效果:

我的原来思路,是让重新渲染一遍,但是没有实现,请大神帮忙解决下
...全文
126 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧