Need to bind foreach and custom attribute to same div

84 Views Asked by At

I have a requirement to bind foreach and one custom attribute(data-tabs-slider-number) to same div using knockout js. I tried like below

  <div data-bind="foreach:{$root.EmployeeoftheMonthItems, 'data-tabs-slider-number': EmployeeoftheMonthItems().length}">

and it's returning error. Please help me

1

There are 1 best solutions below

0
On

You need to use the attr binding for that.

<div data-bind="
    foreach: $root.EmployeeoftheMonthItems,
    attr: {
        'data-tabs-slider-number': $root.EmployeeoftheMonthItems().length
    }"></div>