JABFreeware JABFreeware - 5 months ago 13
JSON Question

Trouble binding complex input to variable, efficiently

I'm new to Angular and trying to learn. I am trying to find a way to bind some Quantities with their IDs. Here is my template:

I have already done a lot of googling and there are tons of resources on how to filter and play with ng-options for ng-repeat but I couldn't find hardly anything about INSERTING the data into the model in a good format.

What am I missing here?

Answer

A possible solution to this exists at http://plnkr.co/edit/9wMZAD?p=info.

These map functions

 vm.endingStructure= _.map(vm.beginningStructure, function(object, value) {
    var newStructure = {};
    newStructure[value] = {
      Details: _.map(object.Details, function(qtyObject, value) {
        var arrayStructure = {
          DetailID: value,
          QTY:qtyObject.QTY
        };
        return arrayStructure;
      })
    };
    return newStructure;
  });

turns { "36": { "Details": { "107": { "QTY": 2323232 }, "108": { "QTY": 232323 } } } } into [ { "36": { "Details": [ { "DetailID": "107", "QTY": 2323232 }, { "DetailID": "108", "QTY": 232323 } ] } } ]