I'm not too good at JS, but still survived. I am creating a kind of complex JS object and want to sort it. The structure of the object is as follows:
cart.attributes = [
{
Attribute,
Value
}
...
];
I create a unique attribute that tells me that three things are separated arbitrarily by a colon:
(product identifier) :( QTY product iterator) :( Attribute name)
QTY product iterator just means that if I have 3 of the same product, then from 3 in the morning I'm talking about the attribute. Each attribute has a meaning.
PROBLEM As you will see from the printout, there is no organization. I would like to sort these results first by using the Product ID, then (QTY Iterator), then alphabetically (Name).
An object is printed here, using the following method to print it, and then the results.
PRINT USE CODE
$.each(cart.attributes, function(attr, value) {
console.log("Attr: "+attr);
console.log("Value: "+value);
});
results
«Attr» 46913872:2:Size
«Value» 10
«Attr» 46913872:2:Hollow-to-Hem
«Value» 57"
«Attr» 46913872:1:Hips
«Value» 34"
«Attr» 46913872:2:Bust
«Value» 34"
«Attr» 46913872:2:Dress Color (hex)
«Value» #FFFFFF
«Attr» 46913872:2:Rush Cut
«Value» Super Rush Cut - 6 weeks
«Attr» 46913872:1:Extra Length
«Value» 5"
«Attr» 46913872:2:Hips
«Value» 34"
«Attr» 46913872:1:Waist
«Value» 29"
«Attr» 46913872:2:Waist
«Value» 23"
«Attr» 46913872:2:Dress Color (name)
«Value» White
«Attr» 46913872:1:Rush Cut
«Value» Super Rush Cut - 6 weeks
«Attr» 46913872:1:Sash Color (name)
«Value» Lipstick
«Attr» 46913872:2:Sash Color (hex)
«Value» #000000
«Attr» 46913872:1:Size
«Value» 14
«Attr» 46913872:1:Hollow-to-Hem
«Value» 58"
«Attr» 46913872:1:Bust
«Value» 35"
«Attr» 46913872:1:Sash Color (hex)
«Value» #B6064C
«Attr» 46913872:1:Dress Color (hex)
«Value» #F9C8D0
«Attr» 46913872:1:Dress Color (name)
«Value» Tea Rose
«Attr» 46913872:2:Extra Length
«Value» 5"
«Attr» 46913872:2:Sash Color (name)
«Value» Black
source
share