Knockout.js - xxxx is not a function

I am trying to enable Knockout.js in WebApplication.

The tutorial in which I'm based on my code is here .

Basically - I have a list of elements - I want to be able to click the element and get the corresponding data in the div at the bottom of the page. In the end, I will use the jquery.UI Dialog plugin to turn this div into a popup, but for now, I'm just trying to get the selected item to work.

My (simplified) code is here: http://jsfiddle.net/fZXAX/1/

I just get the error: actionListViewModel.selectedActionId is not a function.

I do not see the difference between this and a tutorial that uses selectedMailId in the same way. The only difference between my code and the example is that I do not use literal notation.

Can anyone see where I'm wrong? Thanks in advance.

+5
source share
1 answer

Your mistake:

click: function() {actionListViewModel.selectedActionId(id)}

actionListViewModel is a constructor function, but you act as if it were an object.

See this forked jsFiddle . This line that defines the constructor function

function actionListViewModel () {

was modified as an instance of a new object created by calling an anonymous constructor function.

var actionListViewModel = new function () {

and this line where you created an instance of a previously defined function

ko.applyBindings(new actionListViewModel());

, ,

ko.applyBindings(actionListViewModel);

viewModel = new actionListViewModel();, , viewModel actionListViewModel.

+7

All Articles