I want to create a json nested object in angularjs. my object is this:
{ "marketerId": 1, "baskets": [ { "customer": { "phone": "" }, "region": 1, "orders": [ { "bookId": 1, "count": 5 }, { "bookId": 2, "count": 52 } ] }, { "customer": { "phone": "" }, "region": 1, "orders": [ { "bookId": 1, "count": 12 }, { "bookId": 2, "count": 2 } ] } ] }
To create this object, as dynamically, I write this code. As the receipt of orders and items has already been initialized, a form is created. For example, the size of items and orders 2. Is there a better way to create nested json objects?
<input ng-model="formData.marketerId" /> <div class="row" ng-repeat="item in items track by $index"> <input ng-model="formData.baskets[$index].customer.phone" /> <input ng-model="formData.baskets[$index].region" /> <div ng-repeat="order in orders track by $index"> <input type="text" ng-model= "formData.baskets[$parent.$index].orders[$index].bookId"> <input type="text" ng-model= "formData.baskets[$parent.$index].orders[$index].count"> </div> </div>
source share