AngularJS 앱이 있습니다. 내 컨트롤러는 다음과 같습니다 :AngularJS - UI가 제대로 업데이트되지 않습니다.
myApp.controller('MyCtrl', ['$scope', '$http', function ($scope, $http) {
$scope.items = [];
// ProfileUpdate: 0=Not Checked, 1=Checked, 2=Failed, 3=Succeeded
$scope.items.push({
name: 'Chicago Fire', players: [
{ number: 1, profileUpdated:0, name: 'Bill' },
{ number: 2, profileUpdated:0, name: 'John' }
]
});
$scope.items.push({
name: 'Philadelphia Ice', players: [
{ number: 3, profileUpdated:0, name: 'Phil' },
{ number: 4, profileUpdated:0, name: 'Flo' }
]
});
...
$scope.currentTeamIndex = 0;
$scope.currentPlayerIndex = 0;
$scope.execute = function() {
$http.get(playerRelatedUrl)
.then(
function(res) {
$scope.items[$scope.currentTeamIndex].players[$scope.currentPlayerIndex].profileUpdated = 3;
},
function(err) {
$scope.items[$scope.currentTeamIndex].players[$scope.currentPlayerIndex].profileUpdated = 2;
}
)
}
}]);
내 팀은 각 팀을 반복하여 선수 프로필을 업데이트하려고합니다. UI에서 무슨 일이 일어나고 있는지 반영하고 싶습니다. 이 작업을 수행하기위한 노력의 일환으로, 나는 내보기에 다음과 같은 한 :이 코드는 제대로 초기 렌더링
<button ng-click="execute()">Execute</button>
<div ng-repeat="team in items">
<h2>{{team.name}}</h2>
<div ng-repeat="player in team.players">
<ul class="list-inline">
<li>
<div ng-switch="player.profileUpdated">
<h3 ng-switch-when="0">Not checked yet</h3>
<h3 ng-switch-when="1">Checking...</h3>
<h3 ng-switch-when="2">Unable to update</h3>
<h3 ng-switch-when="3">Updated!</h3>
</div>
</li>
<li>{{player.name}}</li>
</ul>
</div>
</div>
. 그러나 실행 버튼이 클릭되면 "확인 중 ..."및 "업데이트 됨"이 나타납니다. 두 번째 또는 두 번째 후에 "Checking ..."이라는 단어가 사라집니다. 몇 가지 조사를 한 후 웹 서비스 호출이 ~ 90 ms에서 실행되고 있다는 것을 알게되었습니다. 그러면 "업데이트 됨"이라는 단어가 왜 그렇게 빨리 나타나는지 설명 할 수 있습니다. 그러나 "Checking ..."이라는 단어가 왜 그렇게 오래 걸리는 이유는 설명하지 않습니다.
누군가 내가 잘못하고있는 것을 설명해 줄 수 있습니까?
감사합니다.
당신이 설정하는 코드를 보여 주시겠습니까 '업데이트의 프로필 = 1 '? 그 논리와 관련 될 수있는 가능성이 있습니다. (미안 내가 그것을 현재의 지위에서 놓쳤다면). 건배, [bro] (http://stackoverflow.com/users/1185425/jquery-mobile). –
악마가 여기에 자세히 나와있을 수 있습니다. 우리는 어떤 유형의 데이터를 다루고 있습니까? 100 팀, 1000 팀? 팀당 얼마나 많은 선수. 팀 당 20 명의 선수를 가진 100 개 이상의 팀이있는 ng-repeat는 문자 그대로 시간의 수천을 소화 할 것입니다. ngRepeat는 성능에있어 막대한 병목 현상으로 알려져 있습니다. 당신의 스코프에 watch 명령문이 있다면, ng-repeat가 스코프 다이제스트를 일으킬 가능성이있는 동일한 양의 시간과 잠재적으로 데이터에 바인딩되고 언 바운드됩니다. – Mutmatt
call $ scope. $ apply(); player.profileUpdated를 설정 한 후 – nacholibre