0

Below I am rendering on the second else an object that contains a string for action.DataBind that renders app.viewModel.members.divisionPools.addPool(); the click event isnt working. Am I doing something wrong?

    {{if action.IsDownload }}
                    <a href="#" data-bind="download: { url: 'members/' + action.Route().toLowerCase() }">${Title}</a>
    {{else action.DataBind}}
                    <a href="#" data-bind="click: action.DataBind">${Title}</a>
    {{else}}
                    <a href="#" data-bind="attr: { href: app.viewModel.members.createRoute(action) }">${Title}</a>
    {{/if}}

app.viewModel.members.divisionPools = {
        addPool: function () {
            alert('test');  
        },
Mike Flynn
  • 22,342
  • 54
  • 182
  • 341

2 Answers2

0

You mention that action.DataBind is a string. This will not work, a 'click' binding expects a function, not a string.

ColinE
  • 68,894
  • 15
  • 164
  • 232
0

If you want to call javascript functions dynamically I would take a look at How do I call a dynamically-named method in Javascript?

In your markup you would have something along the lines of:

<a href="#" data-bind="click: function() { myViewModel.callDynamicFunction($data.action.DataBind) }">

and on your view model add the function:

callDynamicFunction: function(funcName) { .. call function dynamically ... }
Community
  • 1
  • 1
Mark Robinson
  • 13,128
  • 13
  • 63
  • 81