0
在這段代碼中,最後的return false;
做了什麼?流星 - 返回false
Template.register.events({
'submit #register-form': function(event, template) {
event.preventDefault();
// Get input values
var email = template.find('#account-email').value,
password = template.find('#account-password').value;
// Trim and validate Email
var trimInput = function(val) {
return val.replace(/^\s*|\s*$/g, "");
}
var email = trimInput(email);
// Validate Password
var isValidPassword = function(value) {
if (value.length >= 6) {
return true;
} else {
sAlert.error('Your password must be at least 6 characters long');
return false;
}
}
// If Password ok -> Register user
if (isValidPassword(password)) {
Accounts.createUser({
email: email,
password: password
}, function(error) {
if (error) {
// Inform the user that account creation failed
sAlert.error('Account creation failed for unknown reasons');
} else {
// Success. Account has been created and the user
// has logged in successfully.
sAlert.success('Account created successfully');
}
});
}
return false;
}
});
謝謝,您是對的。返回錯誤會告訴事件不實際觸發。 – Edgar
對。這可能是一個更好的方式來把它:)。當我想測試客戶端腳本邏輯,但不想觸發服務器端事件時,我通常會將它放在測試情境中。 – Hill