Estoy estudiando knockout js y ocurrió un error ¿cuál es el problema?
<span data-bind="text: fullname"></span> <script type="text/javascript"> function AppViewModel() { this.firstName = ko.observable('Bob'); this.lastName = ko.observable('Smith'); this.fullname = ko.computed(function() { return this.firstname() + " " + this.lastname(); },this); } // <!-- ko.applyBindings(viewModel); --> var vm = new AppViewModel(); ko.applyBindings(vm); </script>cuando llamo esto,
Uncaught TypeError: this.firstname is not a functionpasar... que pasa?
A
return this.firstname() + " " + this.lastname(); No escribiste con mayúscula la "n" en firstname y lastname . Así que prueba algo como esto:
function AppViewModel() { this.firstName = ko.observable('Bob'); this.lastName = ko.observable('Smith'); this.fullname = ko.computed(function() { return this.firstName() + " " + this.lastName(); },this); } // <!-- ko.applyBindings(viewModel); --> var vm = new AppViewModel(); ko.applyBindings(vm);