각도 js에서 동적으로 생성 된 행렬에있는 텍스트 상자 필드에 값을 할당하는 방법은 무엇입니까?

아야 즈

Angular JS로 동적 행렬을 만들고 있으며, 행렬의 각 셀에는 입력 텍스트 상자가 있으며 모든 텍스트 상자 필드에 대해 ng-model의 동적 이름을 생성 할 수 있습니다. 하지만 선택 상자에서 선택한 옵션에 따라 각 입력 상자의 값을 채우고 싶습니다. ng-change에서 입력 상자를 업데이트하는 함수를 호출했지만 동적 ng-model 이름 때문에 입력 상자에 값을 할당하는 데 놀랐습니다. 내 Html을 참조하십시오.

     <table id="hq-matrix-table" class="table table-bordered">
            <thead>
            <tr class="column-label">
                <td>#</td>
                <td ng-repeat="column in columns">[[column]]</td>
            </tr>
            </thead>

            <tbody class="price-matrix-table">
            <tr ng-repeat="row in rows">

                <td class="row-label">[[row]]</td>

                <td ng-repeat="column in columns" >

                    <div class="input-group" ng-hide="column == '0' && row =='0'">
                        <span class="input-group-addon">$</span>

                       <input ng-model="cells[[row +''+ column]]" id="cell.[[ row ]]_[[column ]]"  ng-class="myVar" ng-click ="myVar='input-matrix'"  placeholder="No Price" type="text" class="form-control" />


                    </div>

                </td>

            </tr>
        </tbody>

        </table>

그리고 선택 상자 변경시

    <select ng-change="updateMatrixCells(section.costPerOption, [[section.id]] )" id="select[[section.id]]"  name="costPerOption" ng-model="section.costPerOption" id="costPerOption" class="form-control selectpicker" data-live-search="true" onchange="$(this).selectpicker('refresh');">
 <option ng-repeat="cost in readyCosts" value="[[ cost.value ]]" >[[ cost.name ]]</option>

Harishr

$ index 행과 $ index 열을 사용하여 업데이트 할 정확한 셀을 가져올 수 있습니다.

<input ng-model="cells[$parent.$index][$index]" ng-class="myVar" 
ng-click ="myVar='input-matrix'"  placeholder="No Price" 
type="text" class="form-control" />

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관