【发布时间】:2016-11-23 06:00:15
【问题描述】:
以下表格显示了提交时的数据列表。当没有提交数据时,我试图显示未找到任何结果。我尝试如下所示,它显示和隐藏了 div。但是当表单上没有选择任何选项并单击提交按钮时,它会显示无结果 div。如何仅在表单验证成功且没有数据可显示时才显示无结果 div。
HTML
<div class="form-group" >
<label class="radio-inline">
<input name="sampleinlineradio" value="3" type="radio" ng-model="radioption"
ng-required="!radioption"> MAIN 1</label>
<label class="radio-inline">
<input name="sampleinlineradio" value="1" type="radio" ng-model="radioption" >
Main 2</label>
<div ng-show="!radioption && buttonClicked">Please select one.</div>
</div>
<div class="form-group">
<label ng-repeat="branch in branches">
<input type="checkbox" name="selectedBranches[]" value="{{branch.value}}"
ng-model="branch.selected" ng-required="isOptionsRequired()" >
{{branch.name}}</label>
<div ng-show="isOptionsRequired() && buttonClicked">Please select one.</div>
</div>
<input type="button" ng-click="fetchresults()" value="submit" >
<div ng-show="buttonClicked">
<table> <thead>.....</thead>
<tbody>
<tr ng-show="results.length!=0" ng-repeat="r in results">
<td></td></tbody></table>
</div>
<div ng-show="buttonClicked">
<span ng-show="results.length==0 ">No results.</span>
</div>
最小控制器代码
$scope.fetchresults = function(){
$scope.results = Result.query({main: $scope.radioption, branch: $scope.selection[0], });
$scope.buttonClicked = true;
}
编辑: 我使用模型进行验证,并且 $valid 也可以正常工作,如下所示。但是出现了一些故障。如果我单击按钮,它不会显示 div。但在验证结束后,它会自动显示之前点击的“无结果”。如何阻止这种情况。虽然它列出了可用的数据,但它会显示“无结果”一秒钟左右
【问题讨论】:
-
如果模型为 null 或为空,则尝试在 click 中传递无线电模型,然后显示表单验证,否则如果您没有结果,则显示未找到结果
-
你能看看下面的答案吗?
-
好的,谢谢。现在检查。