我创建了一个函数名称是rate。当页面加载功能正常时。 Ajax方法正在从API获得结果。当功能完成ng-repeat工作正常时。稍后,当我单击下拉菜单项时,该功能正在运行,但我希望单击下拉菜单项值以插入{{status.value}}。我也有不同的问题。当循环工作时,浏览器冻结。我该如何解决这个问题?
HTML代码
<div class="analysisItem col-sm-6" ng-if="status">
<div class="item">
<div class="dropdown">
<div class="analysisbutton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<div class="container">
<div class="row">
<div class="a col-12">Arz<br><span class="value">{{status.value}}</span><span class="dropdown-arrow"></span></div>
</div>
</div>
</div>
<div class="dropdown-menu w-100">
<a class="dropdown-item" ng-repeat="i in statusRes" data-type="status" data-value="{{i.valueint}}" ng-click="rate();">{{i.value}} <span class="float-right">%{{i.factor}}</span></a>
</div>
</div>
</div>
</div>
JS代码
$scope.type = ["status", "category", "subCategory", "room", "buildingAge", "sfloor", "floor", "square", "price", "currency", "value", "feedback"];
$scope.rate = function (type) {
if (type) $scope.type[type] = type;
for (var i = 0; i < $scope.type.length; i++) {
setTimeout(function (i) {
$scope.params = {
lat: $scope.lat,
lng: $scope.lng,
time: $scope.time,
type: $scope.type[i]
}
$.ajax({
type: 'post',
url: "index.php",
dataType: 'json',
async: false,
cache: false,
xhrFields: {
withCredentials: true
},
data: $scope.params,
success: function (data) {
if (data.response) {
if ($scope.type[i] == "status") {
if (data.response == null || data.response == "") {
} else {
$scope.status = data.response[0];
$scope.statusRes = data.response;
}
}
if ($scope.type[i] == "category") {
if (data.response == null || data.response == "") {
} else {
$scope.category = data.response[0];
$scope.categoryRes = data.response;
}
}
if (!$scope.$$phase) $scope.$apply();
} else if (data.response == null) {
} else if (data.error) {
}
},
error: function (data) {
}
});
}, i * 2000, i);
}
}