Jobert Enamno
Jobert Enamno

Reputation: 4461

Knockout.js Runtime Error

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

enter image description here

Upvotes: 0

Views: 1344

Answers (1)

Jason Li
Jason Li

Reputation: 1585

Seems EmailAddress is not an observable.

Upvotes: 2

Related Questions