我有一个嵌套数组的多个问题和答案,我想禁用用户点击答案时显示的答案。我正在使用Ionic框架。
我已经厌倦了使用ng-disabled
,但无法获得当前显示的按钮以禁用。
数据
$scope.dummyData =
[{
qId:0,
question:"What colour is captain haddock sweater?",
value:2,
answers:
[{
aId:0,
name:"Blue",
value:1
},
{
aId:1,
name:"Yellow",
value:2
},
{
aId:2,
name:"Black",
value:3
},
{
aId:3,
name:"Green",
value:4
}]
}..];
HTML
<ul ng-repeat="obj in dummyData | filterQuestions:[activeQuestion]" >
<li>{{obj.question}}</li>
<ul ng-repeat="answers in obj.answers">
<li>
<br/>
<button class="button button-outline button-stable"
id="answers.aId" ng-click="checkAnswer(answers.value, answers.aId, obj.qId)">
{{::answers.name}}
</button>
</li>
</ul>
</ul>
答案 0 :(得分:1)
尝试:
<ul ng-repeat="obj in dummyData | filterQuestions:[activeQuestion]" >
<li>{{obj.question}}</li>
<ul ng-repeat="answers in obj.answers">
<li>
<br/>
<button ng-disabled="obj.answerChosen" class="button button-outline button-stable"
id="answers.aId" ng-click="checkAnswer(answers.value, answers.aId, obj.qId); obj.answerChosen = true;">
{{::answers.name}}
</button>
</li>
</ul>
</ul>