0

I want to sort the nested array. In order to sort an AFAIK we need to use ArrayController.

I have an arrays, like so :

[{
    id : 1,
    voucherno: 1,
    details : [{id : 3, srno : 3}, {id :2,srno : 2}, {id : 1, srno : 1}]
},
{
    id : 2,
    voucherno: 2,
    details : [{id : 6, srno : 3}, {id : 5, srno : 1}, {id: 4, srno : 2}]
}]

I want to sort the data of details based on srno. After trying various different things this is what Ihave come up with. But it does not work.

My Model is :

App.Sale = DS.Model.extend({
  voucherno : DS.attr('number'),
  details : DS.hasMany('Detail',{ async: true })
});

App.Detail = DS.Model.extend({
  srno : DS.attr('number')
});

Route :

App.Router.map(function() {
this.resource('sales', {
    path: '/'
}, function() {
    this.resource('sale', {
        path: "/:sale_id"
    }, function() {
        this.resource('details');
    });
});
});

Fiddle is here : JSFiddle

Pl help, I saw all the answers around this, but none of them are working for me.

1 Answer 1

2

Corrected you jsfiddle. Rather outlet use {{render}} which also sets the specific controller. Its not sorting issue.

http://jsfiddle.net/11b78Lpz/3/

Basically replaced {{outlet}} which comes to following in sales template.

<script type="text/x-handlebars" data-template-name="sales">
    <div class="container-fluid">
    <div >Voucher No</div>
        <div class="row">
        {{#each model}}
            <div class="row col-md-offset-2 col-md-4 ">{{voucherno}}</div>
            {{render details details}}
        {{/each}}
        </div>
    </div>
</script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.