Reputation: 4461
I'm trying to loop through out the list of items in a collection and compare each item if email address of item to be added on the collection already exist but I got run time error "JavaScript runtime error: Function expected". Please anyone help me what is missing with my code below?
ViewModel
self.AddReceiver = function () {
var newReceiverData = ko.toJS(self.newReceiver);
if (ReceiverValidate()) {
ko.utils.arrayForEach(self.receivers(), function (item) {
if (item.EmailAddress() == newReceiverData.receiveremailaddress) {
alert("Email already exist on the list");
return false;
}
});
self.receivers.push({
EmailAddress: newReceiverData.receiveremailaddress,
FirstName: newReceiverData.receiverfirstname,
LastName: newReceiverData.receiverlastname
});
ClearReceiverInput();
}
};
Screenshot error
Upvotes: 0
Views: 1344