我有一个问题,我需要找到字母表中的字母是真的,哪个是假的。
我无法更改数组$ available(来自回复)。
indexOf不起作用,因为它只查看索引值0& 1但它必须看看值......
任何想法如何解决?
这里是我的伪代码:
var $alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];
var $available = [0: 'a', 1: 'b'];
var $templateglossar = [];
angular.forEach($available, function(letter) {
if($alphabet.indexOf(letter) > -1) {
$templateglossar.push(letter => true);
} else {
$templateglossar.push(letter => false);
}
});
答案 0 :(得分:0)
您的问题有两种可能的解决方案。
1:
<label for="first_name" ng-class="{'form-error':regForm.first_name.$error.required && showRegError}"> First Name </label>
<input name="first_name" id="first_name" type="text" maxlength="50" ng-model="reg.first_name" required="" ng-class="{'form-error':regForm.first_name.$error.required && showRegError}" class="ng-pristine ng-invalid ng-invalid-required">
2:
<label for="first_name" ng-class="{'form-error':regForm.first_name.$error.required && showRegError}" class="form-error"> First Name </label>
<input name="first_name" id="first_name" type="text" maxlength="50" ng-model="reg.first_name" required="" ng-class="{'form-error':regForm.first_name.$error.required && showRegError}" class="ng-pristine ng-invalid ng-invalid-required form-error">
答案 1 :(得分:0)
请注意,您可以在forEach中指定键和值,如下所示:
angular.forEach(objectToIterate, function(value, key) {
/* do something for all key: value pairs */
});
答案 2 :(得分:0)
也许看一下这个lib(lodash):expeccialy到_.difference()方法:
(链接到doc)
https://lodash.com/docs/4.17.4#difference
例如,在你的情况下,例如:
var $alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];
var $available = [0: 'a', 1: 'b'];
var $templateglossar = [];
$templateglossar = _.difference($alphabet, $available);
希望它可以帮到你!!