SharpNoiZy
SharpNoiZy

Reputation: 1119

Knockout, ViewModel is object no computed possible?

I have problem, my Knockout ViewModel is NO function and this IS NEEDED:

vmNeu = {
KdLand: ko.observableArray(),
SelectedKdLand: ko.observable(),


Ansprechpartner: ko.observableArray([]),
ApListe: ko.computed({
    read: function() {
        var apList = [];
        $(this.Ansprechpartner()).each(function(index, ap) {
            var vollerName = ap.Vorname + ' ' + ap.Nachname;
            if (ap.IstStandard) {
                vollerName += ' (Standard)';
            }

            apList.push({ label: vollerName, value: ap.AnsprechpartnerNr });
        });
        return apList;
    }
})

};

Everything until now worked great, observables and subscriptions, but now I want to use an computed and I cant access an other property from my viewModel, I tried everything ;(

Is there a possibility?

Best regards

Upvotes: 1

Views: 788

Answers (1)

Jani Hartikainen
Jani Hartikainen

Reputation: 43243

If you look on the docs for computed observables, you'll see that ko.computed takes an argument for the scope of this. Try changing your code so it works like in the examples and it should work

Upvotes: 1

Related Questions