我想弄清楚为什么这个ng-repeat语句无限运行。 Item.members的长度为2,包含userIds = true
<script type="text/ng-template" id="items_renderer.html">
<label>
<span class="team-description" ng-show="!item.editing">{{item.name}}</span>
<label ng-repeat="memberId in item.members">
<span>{{ getMember(memberId) }}</span>
</label>
</label>
</script>
<div ui-tree="options" class="teamlist">
<ol ui-tree-nodes ng-model="teams" class="panel-teams">
<li ui-tree-node ui-tree-handle
ng-repeat="item in teams"
ng-include="'items_renderer.html'">
</li>
</ol>
</div>
$scope.getMember = (memberId) ->
memberobj = fbutil.syncObject('users/' + memberId)
memberobj.$loaded().then (ref) ->
$scope.teamUser.push ref.name
console.log $scope.teamUser
return $scope.teamUser
它将继续无限期地运行。
<&#34; Sven Woldt&#34;,&#34; Sven Woldt&#34;,&#34; Sven Woldt&#34;,&#34; Sven Woldt&#34;,&#34; Sven Woldt& #34;,&#34; Sven Woldt&#34;,&#34; Sven Woldt&#34;,&#34; Sven Woldt&#34;,&#34; Sven Woldt&#34;,&#34; Yahoo&# 34;,&#34; Yahoo&#34;,&#34; Yahoo&#34;,&#34; Yahoo&#34;,&#34; Yahoo&#34;,&#34; Yahoo&#34;,&# 34; Yahoo&#34;,&#34; Yahoo&#34;,&#34; Yahoo&#34;,&#34; Sven Woldt&#34;,&#34; Yahoo&#34;,&#34; Sven Woldt& #34;,&#34; Yahoo&#34;,&#34; Sven Woldt&#34;,&#34; Yahoo&#34;,...]那我怎么能把这个限制只回归[&#34; Sven Woldt&#34;,&#34; Yahoo&#34;]
感谢您的帮助!
答案 0 :(得分:1)
这是无限期的,因为您一直在推进$scope.teamUser
功能中的$scope.getMember
。如果您只想显示名称,为什么不尝试
$scope.getMember = (memberId) ->
memberobj = fbutil.syncObject('users/' + memberId)
memberobj.$loaded().then (ref) ->
return ref.name
答案 1 :(得分:1)
每当Angular呈现此<span>{{ getMember(memberId) }}</span>
时,您最终(重新)从Firebase加载该成员,从而触发重新呈现。
你的流程是这样的:
getMember
getMember
开始从Firebase加载数据then
$scope
,而{<1}}依次为您的getMember
代码应检查之前是否已加载此成员。如果确实如此,则不应尝试重新加载 - 或者至少不再将其推入$scope
。