So I have an array of objects ex:
var a = {user: [
{year:'1950',name:'Joe'},
{year:'19XX',name:'Chris'},
{year:'1980',name:'Bob'},
{year:'1955',name:'Jan'}
]}
I use this data to template out simple elements holding the year and name. I also have option via a select element to sort this data and then use the sorted to template it out again in order of sort. (bob,chris,jan,joe) or year. But my issue starts with year.
I am needing to continue to use a simple plugin jsonQ (http://ignitersworld.com/lab/jsonQ.html) to edit and sort data, and need to have data for year actually be a little different than desc or asc.
1st I need to edit data at various parts, like year (19XX should become 'Pre 1950'):
//inside ajax success function
var dataObj = jsonQ(data);
dataObj.find('year').value(function (data){
if (data == '19XX') {
return 'pre 1953'
} else {
return data;
}
});
Now I will have a final product data set that needs to be sorted.
var orderedData = dataObj.sort('year', {'order' : 'ASC'});
But this gives me the data back as:
{
user: [
{year:'1950',name:'Joe'},
{year:'1955',name:'Jan'},
{year:'1980',name:'Bob'},
{year:'Pre 1950',name:'Chris'}
]
}
What I need is the data to be returned as:
{
user: [
{year:'Pre 1950',name:'Chris'},
{year:'1950',name:'Joe'},
{year:'1955',name:'Jan'},
{year:'1980',name:'Bob'}
]
}
Any suggestions?