1
votes

I've created a pager template for a knockout viewmodel

<script type="text/html" id="custom_pager_template">

    <ul class="pagination">
        <li class="disabled"><a href="#">&laquo;</a></li>
        <!-- ko foreach: ko.utils.range(0, maxPageIndex) -->\
        <li class="active"><a href="#" data-bind="text: $data + 1, click function() { $root.currentpageindex($data) }, css { selected $data= =$root.currentPageIndex() }"><span class="sr-only"></span></a></li>
        <!-- /ko -->
    </ul>

</script>

But when i run this i get the following error:

Uncaught SyntaxError: Unable to process binding "simpleGrid: function (){return gridViewModel }" Message: Unable to process binding "foreach: function (){return ko.utils.range(0,maxPageIndex) }" Message: Unable to parse bindings. Bindings value: text: $data + 1, click function() { $root.currentpageindex($data) }, css { selected $data= =$root.currentPageIndex() } Message: Unexpected token )

So how can i use ko functions inside a template?

1

1 Answers

0
votes

You're missing twothree colon's

the first 2 are here

css { selected $data= =$root.currentPageIndex() }

should be

css: { selected: $data == $root.currentPageIndex() }

and the final one is here:

click function() { ... }

should be

click: function() { ... }

live example: http://jsfiddle.net/Rkz66/