Program Tip

접두사를 포함하는 knockoutjs로 id 속성 설정

programtip 2020. 10. 26. 08:32
반응형

접두사를 포함하는 knockoutjs로 id 속성 설정


다음과 같이 객체를 반복하기 위해 KnockoutJS를 사용하고 있습니다.

이제이 모든 것이 작동합니다. 하지만 내가 가진 문제 id는의 button를 숫자로 설정한다는 것 입니다. 따라서 다음과 같이 보입니다.

<button id="1">Button 1</button>
<button id="3">Button 2</button>
<button id="8">Button 3</button>

그래서 나는 다음과 같이 'Id'속성 앞에 접두사를 두려고했습니다.

<div data-bind="foreach:Items">
    <button data-bind="text: Name, attr: {'id': 'myprefix_' + Id}"></button>
</div>

그러나 그것은 작동하지 않는 것 같습니다. id내가 그렇게 할 때 Knockout 관찰 가능한 기능으로 가득 차게됩니다 ...

그래서 제 질문은 id필드 속성을 지정할 때 접두사를 어떻게 추가 할 수 있습니까?


경우 Id관측을, 당신해야 "포장을 벗긴"그것은 : 'myprefix_' + Id().


실제로 오늘 이것을 사용했습니다-내가해야 할 관찰 대상을 풀기 위해 :

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

도움이 되었기를 바랍니다.


예를 들어 $ index를 사용하는 것이 가장 좋습니다.

<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;">

참고 URL : https://stackoverflow.com/questions/12508404/setting-the-id-attribute-with-knockoutjs-include-a-prefix

반응형