在 AngularJS 中保存在 ng-repeat 中生成的字段 (Saving a field generated in ng-repeat in AngularJS)


問題描述

在 AngularJS 中保存在 ng‑repeat 中生成的字段 (Saving a field generated in ng‑repeat in AngularJS)

所以,我需要在數組中保存 ng‑repeat 中生成的每個字段的數據。我的代碼看起來像這樣:

<tr ng‑repeat = "feature in filteredFeatures">
        <td>{{feature.name}}</td>
        <td><input type="number" ng‑model=""></td> 
</tr>

所以,無論用戶在輸入字段上寫什麼,我都希望保存它,但我當然不知道如何保存。


參考解法

方法 1:

Just add a model to ng‑model in the input

<tr ng‑repeat = "feature in filteredFeatures">
    <td>{{feature.name}}</td>
    <td><input type="number" ng‑model="feature.name"></td> 
</tr>

方法 2:

All right it wasn't that hard after all. As suggested I put an array via ng‑model, but the trick was in using $index (I had no idea I could use it). So the code ended looking like this:

<table class="table">
     <tr>
        <th>Feature</th>
        <th>Result</th>
     </tr>  
      <tr ng‑repeat = "feature in filteredFeatures">
        <td>{{feature.name}}</td>
        <td><input type="number" ng‑model="measures[$index]"></td> 
      </tr>

    </table>

So, hope I can help someone in the future, and thank to everyone who provided a little bit of their time.

(by Gabo EremitastalinGabo Eremita)

參考文件

  1. Saving a field generated in ng‑repeat in AngularJS (CC BY‑SA 2.5/3.0/4.0)

#ng-repeat #javascript #angularjs #save






相關問題

ng-repeat 加載後不顯示表行 (ng-repeat not showing table rows after loading)

僅在 ng-repeat 中將 ng-if 應用於所選項目 (Apply ng-if in ng-repeat only to selected item)

AngularJS:獲取複雜過濾數組的大小 (AngularJS: Get size of complex filtered array)

單擊時更改 ng-class(嵌套 ng-repeat) (Changing ng-class when clicked (nested ng-repeat))

帶有選擇/選項下拉框的嵌套 ng-repeat 問題 (Nested ng-repeat issue with select/options drop down box)

錯誤:[ngRepeat:dupes] 不允許在轉發器中重複。使用“track by”表達式指定唯一鍵 (Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys)

在 AngularJS 中保存在 ng-repeat 中生成的字段 (Saving a field generated in ng-repeat in AngularJS)

遍歷對像數組以構建 div 結構 (Iterate over array of object to build a div structure)

ng-repeat 中 IE 下拉列表中的 Angularjs 無法正確呈現 (Angularjs in IE dropdowns in ng-repeat do not render correctly)

動態 ng-repeat 表單的優雅解決方案 (Elegant solution for a dynamic ng-repeat form)

如何區分 Rs 和 % 值? (How to differentiate Rs and % values?)

難以為一組對象運行 ng-repeat (difficulty running ng-repeat for an array of objects)







留言討論