我在Javascript中编写一个简单的for循环。它有效,但现在我想添加一个选项,如果for循环中的条件不满足则触发它。如果我在for循环中放入了else条件,它就会被触发' i'倍。我如何制作它? '破发'不会做的伎俩,因为它会完全停止for循环。如何进行for循环检查' i'如果满足条件,并且如果不符合条件,则为“时间”。做一些事情。感谢
onClickContact : function(component, event, helper){
var accountInfo = component.get('v.accountInfo');
var mailTo = component.get('v.mailTo');
for ( var i = 0; i < mailTo.length; i++) {
if ( mailTo[i].Country__c == Account.BillingCountry){
window.location.href = mailTo[i].Mailto__c;
}
}
}
答案 0 :(得分:0)
onClickContact : function(component, event, helper){
var accountInfo = component.get('v.accountInfo');
var mailTo = component.get('v.mailTo');
for ( var i = 0, var k = false; i < mailTo.length; i++) {
if ( mailTo[i].Country__c == Account.BillingCountry){
window.location.href = mailTo[i].Mailto__c;
k = true;
}
if(i == mailTo.length-1 && !k) {
/* your code if the condition isn't met at all.*/
}
}