I'm doing an app with Ionic and I need to store date in my firebase. But it's getting out of order, i tried methodos like orderByChild(); but nothind is working.
I need my firebase to store like this:
- 1 Mar 2018
- 5 Mar 2018
- 10 Mar 2018
Instead its keeping like this:
- 1 Mar 2018
- 10 Mar 2018
- 5 Mar 2018
There's anyway that I can get it in order?
Here's where I got my date:
function getCurrentDate(){
var today = new Date();
console.log(today.getMonth());
var dd = today.getDate();
var mm = today.getMonth(); //January is 0!
var month = new Array();
month[0] = "Jan";
month[1] = "Fev";
month[2] = "Mar";
month[3] = "Abr";
month[4] = "Mai";
month[5] = "Jun";
month[6] = "Jul";
month[7] = "Ago";
month[8] = "Set";
month[9] = "Out";
month[10] = "Nov";
month[11] = "Dez";
var yyyy = today.getFullYear();
var currentDate = dd+" "+month[mm]+' '+yyyy;
return currentDate;
}
Here's where I push into firebase:
function AddServico(date,finalValue,id){
var deffered = $q.defer();
var ref = fb.child('/Barbeiro/'+id+'/Dia/'+date+'/');
ref.once("value")
.then(function(snapshot) {
ref.push().set({'finalValue':finalValue});
deffered.resolve(snapshot);
});
ionicToast.show('Adicionado', 'middle', false, 1500);
return deffered.promise;
}
And here is where I read it from firebase:
function GetDias(id){
var query = fb.child('Barbeiro/'+id+'/Dia/');
return $firebaseArray(query).$loaded();
}
Here is how my firebase keep it:
Here's how my app shows it :