[英]How can I completely exit from inside a .forEach that is inside a function
I have this method: 我有这种方法:
wordFormDirty = (): boolean => {
var self = this;
angular.forEach(self.word.wordForms, function (wf, key) {
var wordFormNgForm = 'wordFormNgForm_' + wf.wordFormId
if (!self[wordFormNgForm].$pristine) {
return true;
}
});
return false;
};
From what I see this never returns true. 从我的角度来看,这永远不会返回true。 Can someone give me advice as to how I can implement this so that a form that's not pristine will make the wordFormDirty() method return true.
有人可以给我一些建议,让我了解如何实现此方法,以便不是原始格式的表单使wordFormDirty()方法返回true。
If you wish to get a result directly from walking the Array
, consider using other methods than forEach
. 如果希望直接通过遍历
Array
获得结果,请考虑使用forEach
以外的其他方法。 Eg: 例如:
return Object.values(this.word.wordForms).some(
({ wordFormId }) => !this[`wordFormNgForm_${wordFormId}`].$pristine
);
can you try this, in this case, if I've undestand the issue, the first time there is a value true the result is set to true otherwise it remains false 您能尝试这种情况吗?在这种情况下,如果我无法理解问题,那么第一次出现值true时,结果将设置为true,否则将保持为false
wordFormDirty = (): boolean => {
var self = this;
var result = false;
angular.forEach(self.word.wordForms, function (wf, key) {
var wordFormNgForm = 'wordFormNgForm_' + wf.wordFormId
if (!self[wordFormNgForm].$pristine) {
result = true;
}
});
return result;
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.