0

I have angular app that user dynamic form field adding

HTML

<div class="sub_skus">
  <div class="select-style">
    <select data-ng-options="unitP as unitP.name for unitP in unitProducts" data-ng-model="choice.subProduct[choice.id]" data-ng-change="getUnitProductData(choice.id)">
    </select>
  </div>
</div>

<div class="sub_skus">
  <input type="text" data-ng-model="choice.subSku">
</div>
<div class="sub_skus">
  <input type="text" data-ng-model="choice.price" placeholder="Price">
</div>
<div class="sub_skus">
  <input type="number" data-ng-model="choice.quantity" placeholder="Quantity">
</div>

<div>
  <span ng-show="$last" ng-click="removeChoice()" class="input-group-addon a1 vd_bg-red vd_white rmMainIcon">
      <i class="fa fa-minus"></i>
   </span>
</div>
</div>

JS

$scope.unitProducts = {};
productService.getUnitProducts().then(function success(responce) {
  $scope.unitProducts = responce.data.units;
  console.log($scope.unitProducts);
});

$scope.choices = [{
  id: '1'
}];

$scope.addNewChoice = function() {
  var newItemNo = $scope.choices.length + 1;
  $scope.choices.push({
    'id': newItemNo
  });
};

$scope.removeChoice = function() {
  var lastItem = $scope.choices.length - 1;
  $scope.choices.splice(lastItem);
};

when I select one option from select it will get below data from the service

[{"id":"1","subProduct":{"1":{"id":"15","name":"rrrr","sku":"rf","price":"3.00"}}}]

I want to set that above data to sku to choice.subSku and price to choice.price inside the loop ?

Upalr
  • 2,140
  • 2
  • 23
  • 33
Miuranga
  • 2,463
  • 10
  • 51
  • 81
  • What do you mean by `inside loop` ? Do you want to set the selected value into `choice.subProduct[choice.id]` in specific format ? – Tasnim Reza Oct 20 '15 at 06:59

1 Answers1

1

I would suggest please try on JSON.simple is a simple Java library for JSON processing, read and write JSON data and full compliance with JSON specification (RFC4627).

There is a lot of example's avaliable in net .Please surf it . I am also attached some usefull stack over flow and other links are

java-iterate-over-jsonobject - How to iterate over a JSONObject?

json-simple-example-read-and-write-json - http://www.mkyong.com/java/json-simple-example-read-and-write-json/

how-to-access-nested-elements-of-json-object-using-getjsonarray-method - How to access nested elements of json object using getJSONArray method

how-can-i-iterate-jsonobject-to-get-individual-items - How can I iterate JSONObject to get individual items

Community
  • 1
  • 1
SakthiSureshAnand
  • 1,324
  • 16
  • 32