Ryan Blue Ryan Blue - 24 days ago 13x
HTML Question

Javascript function calls from knockout.contextmenu

I have the following chunk of HTML code. I am attempting to use knockout.contextmenu to have dynamic context menu functions from knockout observables.

The first (The one with the context menu) gives me a "Uncaught TypeError: string is not a function."
The second works.

(To clarify, the context menu generates correctly in the first td, it gives me the uncaught error when I click one of the options)

I cannot figure out what the difference between the $parent.selectLan in the first td and the $parent.selectLan in the second td is.

I have included the relevant pieces of the js and the html code in question.

Any help from someone who has dealt with this before would be appreciated!
(For reference, knockout.contextmenu is here: https://github.com/nescalante/knockout.contextmenu)


<tbody data-bind="foreach: lans">
<td align="left" data-bind="text: name, contextMenu: { 'Node View': $parent.selectLan, 'Process View': $parent.selectLan }, bindMenuOnClick: true"></td>
<td align="left" data-bind="text: name, click: $parent.selectLan"></td>


this.selectLan = function () {

console.log("Selecting LAN: " + this.name());
clickedLan = this.name();
console.log("dynamicLanCount is : " + dynamicLanCount);


Current model is passed as a first parameter the the click handler:

this.selectLan = function (lan) {

        console.log("Selecting LAN: " + lan.name()); // <- lan instead of this
        clickedLan = lan.name();
        console.log("dynamicLanCount is : " + dynamicLanCount);