gpt4 book ai didi

javascript - ng-show 功能不起作用

转载 作者:行者123 更新时间:2023-12-02 15:12:14 24 4
gpt4 key购买 nike

当函数返回 1 时,应该显示 h2,但即使它返回 1,它也不会显示标题。

以下 Angular 代码:

<md-virtual-repeat layout-wrap class="toast" ng-repeat="member in members| filter:searchText | orderBy:orderByFunction" >
<div class="subtitle" ng-show="showContrib(member) == 1" >
<h2> CONTRIBUTORS {{member.price}} -- {{member.amount}}</h2>
</div>
<div class="subtitle" ng-show="showTop(member) == 1" >
<h2> TOP CONTRIBUTORS {{Number(member.price)}} -- {{Number(member.amount)}}</h2>
</div>
<md-whiteframe class="md-whiteframe-z3 frieed" style="margin:6px; padding: 19px;" flex-sm="35" flex-gt-sm="25" flex-gt-md="20" layout layout-align="center center">
{{ member.amount}}
</md-whiteframe>
</md-virtual-repeat>

使用这个js代码:

$scope.showTop = function(member){
if($scope.topShow == 1){

return 0;
}
if(parseInt(member.price) < parseInt(member.amount)){
console.log('came here price');
$scope.topShow = 1;
return 1;

}
return 0;

};
$scope.showContrib = function(member){
$scope.conShow = 1;
// console.log('price='+member.price+"amount"+member.amount);
if($scope.conShow == 1){
return 0;
}
if(parseInt(member.price) == parseInt(member.amount)){
$scope.conShow = 1;
return 1;

}
return 0;

};

即使我可以在 console.log 中看到 topShow 和 conShow 更改为 1,它的计算结果始终为 false。

最佳答案

这里有两个问题。

正如 @LokiSinclair 指出的,其中一个是 $scope.showContrib 将始终返回 0。

第二,是ng-show中函数的使用。当您使用函数来确定 ng-show 的值时,该函数将一遍又一遍地重新计算。在您的 $scope.showTop 函数中,您将 $scope.topShow 的值更改为 1 并返回 1,但由于您更改了作用域对象的值,因此它可以再次调用此函数只需几毫秒,只不过这次它会返回 0。

关于javascript - ng-show 功能不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34738186/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com