Sorting in ember using multiple array

by skskumbharkar

HTML

<script src="http://builds.emberjs.com/handlebars-1.0.0.js"></script>
<script src="http://builds.emberjs.com.s3.amazonaws.com/ember-1.0.0-rc.7.js"></script>
<script src="http://builds.erikbryn.com/ember-model/ember-model-latest.js"></script>
<script type="text/x-handlebars" data-template-name="index">
    {{view Ember.Select
    contentBinding="sortingOptions"
    optionValuePath="content.id"
    optionLabelPath="content.option"
    valueBinding="sortingMethod"
    }}	
    
    <ul>
    
        {{#each Astcart.IndexController}}  
        <li>
            {{id}}
        </li>
        {{/each}}
    
    </ul>
</script>

JavaScript

Astcart = Ember.Application.create({});

Astcart.IndexRoute = Ember.Route.extend({
    model: function() {
        return Astcart.Application.find();
    }
}); 

Astcart.IndexController = Ember.ArrayController.extend({
    result : function() {
            this.get('model').map(function(application) {
			    return application.get('home_products');
	        });
    },   
    content: this.result(),
    sortingMethod: 0,
    sortingOptions: [
        {option: "Best Match",  id: 0, property: 'id', asc: true},
        {option: "Low to High", id: 1, property: 'id', asc: true},
        {option: "High to Low", id: 2, property: 'id', asc: false}
    ],
    currentOption: function() {
        return this.get('sortingOptions')[this.get('sortingMethod')];
    },
    sortProperties: function() {
        
        return [this.currentOption().property];
    }.property('sortingMethod'),
    sortAscending: function() {
        return this.currentOption().asc;
    }.property('sortingMethod')
});

	Astcart.Application =  Ember.Model.extend({
		name: Ember.attr(),
        home_products: Ember.hasMany('Astcart.Home_products', {key: 'home_products', embedded: true})
	});
	
	Astcart.Home_products = Ember.Model.extend({
		id: Ember.attr(),
		name: Ember.attr()
	});	

	Astcart.Application.adapter = Ember.FixtureAdapter.create();
    
Astcart.Application.FIXTURES=[
{
    "name" : "astr",
    "home_products": [
        {
            "id": 3,
            "name": "Mobiles & Accessories"
        },
        {
            "id": 2,
            "name": "Mobiles & Accessories"
        },
        {
            "id": 1,
            "name": "Mobiles & Accessories"
        }
    ]
}
];