0

I am using knockout to dynamically create a div and bind array items as follows:

<div data-bind="template:{name:'person-template',foreach:$data[1],afterrender:sample}">

<script type="text/html" id="person-template">
<div id="uniqueid">
</div>
</script>

I am in confusion as how to generate the unique ids for divs created. Can you one give an idea?

user1400915
  • 1,933
  • 6
  • 29
  • 55

1 Answers1

0

You can use uniqueName binding. Even better the uniqueId binding.

There are other different ways to implement this functionality, as pointed @haim770 and discussed in other threads on SO - Setting the id attribute with knockoutjs including a prefix.

Community
  • 1
  • 1
TSV
  • 7,538
  • 1
  • 29
  • 37