Setting the id attribute with knockoutjs including a prefix

人走茶凉 提交于 2019-11-30 07:47:41

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

Cordell Lawrence

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

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

Hope this helps.

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>

       <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;">
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!