Setting the id attribute with knockoutjs including a prefix

后端 未结 4 619
天涯浪人
天涯浪人 2020-12-30 18:04

I\'m using KnockoutJS to iterate over an object, like this:

Now this all works. But the problem i have is that it sets the id of the butto

相关标签:
4条回答
  • 2020-12-30 18:41

    I think it's best to use the $index for example

    <div data-bind="foreach:Items">
        <button data-bind="text: Name, attr: {id: 'myprefix_' + $index() }"></button>
    </div>
    
    0 讨论(0)
  • 2020-12-30 18:49

    If Id is an observable, you must "unwrap" it: 'myprefix_' + Id().

    0 讨论(0)
  • 2020-12-30 18:50

    Actually used this today - to unwrap the observable I had to do:

    <button data-bind="attr: { id: 'prefix_' + $index() }"> Send </button>
    

    Hope this helps.

    0 讨论(0)
  • 2020-12-30 19:04

           <img data-bind="event: {click: $root.afficherDetailmembreFamille}" src="ucc/gestion_Famille/images/arbre-fleche-off.png" />
    
              <label data-bind=" text: nom"></label>
              <label data-bind=" text: prenom, click: $root.afficherDetailmembreFamille"></label>
      <br>
    
       <div data-bind="attr: {'id': 'DivMembreFamille'+id}" style="margin-left: 40px; display: none;">
    
    0 讨论(0)
提交回复
热议问题