I have list of price which i want to sort based on selection of drop down.I want to sort data in both ways ascending and descending.
On selection of "Low to high", I want to sort list of price in descending order and on selection of "High to low", I want to sort list of price in ascending order.
Here,I am passing Application
fixture to model of index
route and in Astcart.IndexController
i am trying to sort data but it is throwing an error Uncaught TypeError: Object [object Object] has no method 'sort'
Astcart.IndexRoute = Ember.Route.extend({
model: function() {
return Astcart.Application.find();
}
});
Astcart.IndexController = Ember.ArrayController.extend({
sortingMethod: null,
sortingOptions: [
{option: "Best Match", id: 0},
{option: "Low to High", id: 1},
{option: "High to Low", id: 2}
],
sortProperties: ['product_price'],
sortAscending: true,
sortingMethodDidChange: function() {
if(this.get('sortingMethod') == 1){
alert("sort data in descending order");
}else if (this.get('sortingMethod') == 2){
alert("sort data in ascending order");
}
var content = this.get("content");
this.set('content', Ember.copy(content.sort(), true));
}.observes('sortingMethod')
});
Fixture :
Astcart.Application.adapter = Ember.FixtureAdapter.create();
Astcart.Application.FIXTURES=[
{
"home_products": [
{
"id": "1",
"name": "Mobiles & Accessories",
"contents": [
{
"id": "1",
"price": "1"
},
{
"id": "2",
"price": "2"
},
{
"id": "3",
"price": "3"
},
{
"id": "4",
"price": "4"
}
]
},
{
"id": "2",
"name": "Mobiles & Accessories",
"contents": [
{
"id": "41",
"price": "5"
},
{
"id": "5",
"price": "6"
},
{
"id": "6",
"price": "7"
},
{
"id": "7",
"price": "8"
}
]
},
{
"id": "3",
"name": "Mobiles & Accessories",
"contents": [
{
"id": "8",
"price": "9"
},
{
"id": "9",
"price": "10"
},
{
"id": "10",
"price": "11"
},
{
"id": "11",
"price": "12"
}
]
}
]
}
];
I have posted complete code here(jsfiddle). Can any help me to make this jsfiddle work?