0

I'm writing a small application in JS and I decided to use Knockout. Everything work well except from a single value that is not printed correctly and I don't understand why.

This is the html view where error appends (viaggio.arrivo is not visualized, and in place of correct value appears a function code like this "function c(){if(0 <arguments.length){if ..." and so on)

<input data-bind="value: viaggio.arrivo"  />

And this is the javascript View Model. Code is pretty long so I put it in a jsFiddle.

     function ViewModel() {
        function Viaggiatore(nome, cognome, eta, citta) {
            var self = this;
            self.nome = nome; self.cognome = cognome;
            self.eta = ko.observable(eta);
            self.citta = ko.observable(citta);
        }
        function Viaggio(viaggiatore, partenza, arrivo, mete) {
            var self = this;
            self.viaggiatore = ko.computed(viaggiatore);
            self.partenza = ko.computed(partenza);
            self.arrivo = ko.observable(arrivo);
            self.mete = ko.computed(mete);
        }

        self.viaggiatore = new Viaggiatore("Mario", "Rossi", 35, "Como");
        self.viaggio = new Viaggio(
            function(){ return self.viaggiatore.nome+" "+self.viaggiatore.cognome; },
            function(){ return self.viaggiatore.citta; },
            "Roma",
            function(){ return "mete" ;}
        );          
    }
    ko.applyBindings(new ViewModel());

1 Answer 1

1

I think you need brackets on one of your parameters, like so:

<p data-bind="text: viaggio.partenza()"></p>

Check out the updated fiddle: http://jsfiddle.net/mGDwy/2/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.