Search code examples
javascriptjqueryractivejs

RactiveJS events on tripple mustache


I have a paging function since it's a little bit tricky to do it in the templates. The problem is that if I place it like this:

{{ paging( rows, limit, offset ) }}

It will obviously escape the output , so I tried with triple-stache and the output is as expected. But then, it wont detect on-click events anymore.. any suggestions ?

A workaround I thought about is setting jQuery to detect the click event on the .pagination > li but I just wanted to ask if there's any way RactiveJS can do that for me or I'm just missing something.

Have a great day !


Solution

  • Use a partial if you want to add dynamic templating:

    data: {
        foo: 'foo',
        paging: function(x){
            var template = '<li on-click="clicked()">' + x + '</li>';
            if (!this.partials.paging) {
                this.partials.paging = template;
            }
            else {
                this.resetPartial('paging', template);
            }
            return 'paging';
        }
    },
    

    See http://jsfiddle.net/fz7adjm4/