[英]AngularJS Collect Data from table - parse into JSON
我如何能夠從表中收集所有數據,然后將其解析為JSON,然后再將其寫入屬性文件?
的HTML
<table class="table">
<thead>
<tr>
<th>Key</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="(key, value) in configResources">
<td>{{key}}</td>
<td><input type="text" value={{value}}></td>
</tr>
</tbody>
</table>
<button class="btn btn-primary" ng-click="changeProp()"></button>
JS
$scope.changeProp(){
//collect data then parse as JSON
};
將您的value={{value}}
切換為ng-model="value"
,這樣,當您更改值時,您的數據將自動更新,並且您只需要在需要時就可以調用angular.toJson($scope.configResources)
將其轉換為JSON。
開關
<input type="text" value={{value}}>
至
<input type="text" ng-model="value" />
然后,執行以下操作:
$scope.changeProp(){
var myJson = angular.toJson($scope.configResources);
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.