简体   繁体   中英

AngularJS Collect Data from table - parse into JSON

How would I be able to collect all the data from the table then parse it into a JSON so I could then write it to a properties file?

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。

switch

<input type="text" value={{value}}>

to

<input type="text" ng-model="value" />

and then, do the following:

$scope.changeProp(){
     var myJson = angular.toJson($scope.configResources);
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM