我试图根据其他问题的答案对ng-repeat中的问题进行条件可见性。如果用户来自加拿大然后显示省份,如果用户来自美国,则显示州。我目前的尝试在ng-show中是这样的:
survey[question.otherquestionToTest - 1].answer == question.testedCondition
我试着用描述性的术语来解释我想要做什么。我仍然熟悉Angular,我不确定是否有更好的方法来完成这项工作。如果这似乎是处理这个问题的低效方法,那么任何人都可以提出任何其他选择。
以下是我的控制器和html的示例。
CONTROLLER
angular.module('myApp')
.controller('UserInfoCtrl', function ($scope) {
$scope.userInfo = {
userSurvey: [
{ // Question 8
question: 'What country do you live in?',
answer: '',
options: [
'Canada',
'USA'
]
},{ // Question 9
visibilityDependentOnQuestion: 8,
visibilityCondition: 'Canada',
question: 'What province do you live in?',
answer: '',
options: [
'Alberta',
'British Columbia',
'Manitoba',
'New Brunswick'
]
},{ // Question 10
visibilityDependentOnQuestion: 8,
visibilityCondition: 'USA',
question: 'What state do you live in?',
answer: '',
options: [
'Alabama',
'Alaska',
'Arizona',
'Arkansas'
]
}
]
};
});
查看
<form class="form-horizontal">
<div class="form-group ng-hide"
ng-repeat="(key, userInquery) in userInfo.userSurvey as survey"
ng-show="survey[userInquery.visibilityDependentOnQuestion - 1].answer == userInquery.visibilityCondition">
<label class="col-sm-4 control-label text-right">{{userInquery.question}}</label>
<div class="col-sm-4">
<select class="form-control" ng-model="userInquery.answer">
<option ng-repeat="option in userInquery.options">{{option}}</option>
</select>
</div>
</div>
</form>
答案 0 :(得分:4)
最好过滤结果而不是隐藏它。请改用过滤器。您需要在填充时按日期添加过滤器。
在这里,您可以通过visibilityCondition应用过滤器。
像这样的东西
async.each(crawlCities, function (city, cb) {
var temp = city + ".craigslist.org";
queue.push({
url: "http://" + temp + crawlTask.path,
domain: temp,
taskId: crawlTask.taskId
}, handler);
setTimeout(cb, 20000);
}, function (err) {
console.log("Something went wrong", err);
});