I have x ng-repeats inside an another ng-repeat list, like so:
<div ng-repeat="object in objects">
<div ng-repeat="item in object">
<a href="{{url}}"><p>{{title}}</p></a>
</div>
<div ng-repeat="item in object">
<a href="{{url}}"><p>{{title}}</p></a>
</div>
<div ng-repeat="item in object">
<a href="{{url}}"><p>{{title}}</p></a>
</div>
</div>
The data comes from a JSON object that contains other objects, which contains the content I'm rendering in the ng-repeat, like so:
var data = [
{Object
{ subObject {entries:
{title:'he', desc:'for male'}
}
} ,
{ subObject {entries:
{title:'she', desc: 'for female'},
}
} ,
{ subObject {entries:
{title: 'I', desc: 'for me'}
}
}
}
I'm trying to render the content of all <div ng-repeat="item in object">
shuffled and without altering the JSON Object. I tried some shuffling functions like following (i found it in SO):
// -> Fisher–Yates shuffle algorithm
var shuffleArray = function(array) {
var m = array.length, t, i;
console.log('executing');
// While there remain elements to shuffle
while (m) {
// Pick a remaining element…
i = Math.floor(Math.random() * m--);
// And swap it with the current element.
t = array[m];
array[m] = array[i];
array[i] = t;
}
And calling it like this shuffle(objects);
on the controller, but obviously I only get the blocks objects inside the main Object randomized, not the content itself. The problem is that I don't know how to 'decompose' the object or merge the inside objects into one, to shuffle it.
I also tried to shuffle the ng-repeat data once it is created in the DOM, but I couldn't find a way to merge ng-repeat data. I'm just learning AngularJS so I don't know if this is the better way to accomplish what I need. How should this be done? Thanks ;D