Javascript 在删除旧列表之前,重新加载ng repeat将呈现新列表
我需要用ng重复测量包含LI的UL的宽度 第一次它工作得很好。然而,当重新加载数据时,宽度是实际宽度的两倍,我相信这是由于在删除旧的LI之前对新的LI进行了角度渲染 在渲染新的之前,如何先删除旧的LI 另外,如果我将超时设置为1000,它可以正常工作,但是我不想每次都等1秒钟Javascript 在删除旧列表之前,重新加载ng repeat将呈现新列表,javascript,angularjs,ng-repeat,Javascript,Angularjs,Ng Repeat,我需要用ng重复测量包含LI的UL的宽度 第一次它工作得很好。然而,当重新加载数据时,宽度是实际宽度的两倍,我相信这是由于在删除旧的LI之前对新的LI进行了角度渲染 在渲染新的之前,如何先删除旧的LI 另外,如果我将超时设置为1000,它可以正常工作,但是我不想每次都等1秒钟 <ul class='ul'> <li ng-repeat="thing in data.things" class="buyer_li" ng-init="$last && g
<ul class='ul'>
<li ng-repeat="thing in data.things" class="buyer_li" ng-init="$last && getUlWidth()">
<p>{{thing.detail}}
</li>
</ul>
<button ng-click="reloadData()">Reload</button>
$scope.getUlWidth = function(){
setTimeout(function() {
$scope.ulWidth = document.querySelector('.ul').clientWidth;
}, 0);
}
$scope.reloadData = function(){
//reloadDataFunc;
}
-
{{thing.detail}}
重新加载
$scope.getUlWidth=function(){
setTimeout(函数(){
$scope.ulWidth=document.querySelector('.ul').clientWidth;
}, 0);
}
$scope.reloadData=函数(){
//重新加载数据函数;
}
我想可能是您的CSS用于布局,不太确定。但我想包括一个可能有帮助的
函数exampleController($scope,exampleFactory,$timeout){
$scope.list=[];
$scope.listContainerWidth='???';
$scope.refreshList=函数(){
$scope.list=[];
$scope.listContainerWidth='???';
$scope.listContainerWidth=document.querySelector('.ul').clientWidth;
$timeout(函数(){
getList();
}, 1000);
};
函数getList(){
示例工厂
.getList()
.then(功能(列表){
$scope.list=列表;
});
}
getList();
}
函数exampleFactory($http){
变量根http://jsonplaceholder.typicode.com';
函数getList(){
返回$http.get(root+'/comments')
.然后(功能(resp){
返回相应的数据;
});
}
返回{
getList:getList
};
}
有棱角的
.module('应用程序',[])
.controller('exampleController',exampleController)
.工厂(“exampleFactory”,exampleFactory)代码>
。容器流体{
背景色:#1D1F20;
颜色:#fff;
字体大小:14px;
字体大小:粗体;
钮扣{
利润率最高:20%;
}
}
ulli{
列表样式:无;
利润率:10px;
}
.child padding>div{
填充:2px;
}
.col-md-2{
位置:固定;
钮扣{
利润底部:10%;
}
}
.圆界{
浮动:左;
文本对齐:居中;
边界半径:50%;
宽度:25%;
背景色:#0bf;
}
刷新注释列表
-
我找到了发生这种情况的原因,因为我没有通过任何方式跟踪ng repeat,添加=通过$index跟踪解决了问题
查看此问题和答案您的CSS布局是什么样子的?