0

Data normalization from two dimensional to 1 dimension using lodash

rel      href

link1    url1

link2    url2

link3    url3  url4

link4    url4  url5

Expected after Normalization

rel      href

link1    url1

link2    url2

link3    url3 

link3    url4

link4    url4 

link4    url5

I create a file here but it didn't give me expected result using lodash methods

http://plnkr.co/edit/jijIkVwOLDSoA8IhiNc6?p=preview

function update(data) {
     for (var i = 0; i < data.length; i++) {
                if (data[i].href.length > 1) {
                    var a = data[i].href.length;
                    for (var j = 0; j < a; j++) {
                        updatedata.push(data[i]);
                    }
                }
            }
    return updatedata;
}

var updatedata=[{ rel: '', href: []}];

var data = [
    { rel: 'link1', href: ['url1']},
    { rel: 'link2', href: ['url2']},
    { rel: 'link3', href: ['url3' , 'url6']},
    { rel: 'link4', href: ['url4' , 'url5']}
];

console.log(update(data));
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • You changed the entire question...please marked it as answered and make a new question instead....our answers don't make any sense in this context now. – deek Aug 20 '15 at 22:35

2 Answers2

0

You should be able to use a nested ng-repeat for the addresses per user and can conditionally show/hide it if you want on click. If you share your code in a snippet here with the problem (or in plnkr.co) then I can show a fixed version.

shaunhusain
  • 19,630
  • 4
  • 38
  • 51
0

m59 does a much better job here of explaining

how to split the ng-repeat data with three columns using bootstrap

you can filter the results via a controller and return an array containing objects(each address) and ng-repeats uses this to generate rows. two way binding the address input to will allow ng-repeat to dynamically create rows as the user types!

Community
  • 1
  • 1
deek
  • 1,085
  • 1
  • 9
  • 27
  • Thanks for your answer. I just update the question please take a look. – user2333761 Aug 20 '15 at 21:26
  • You added lodash....do you even need it? Your code is much more complicated than it needs to be. I'm on a phone so I can't code much but it seems unnecessarily complex – deek Aug 20 '15 at 22:19
  • Can u give me a simple approach? – user2333761 Aug 21 '15 at 00:50
  • Follow the link I posted. BTW, you could try pushing all urls into one array. Then a function inserts them sequentially into the final data object. – deek Aug 21 '15 at 16:53