Data example, where VoucherRedeemed
is a checkbox
value:
{
VoucherTitle: "title 2",
VoucherRedeemed: false,
},{
VoucherTitle: "title 4",
VoucherRedeemed: true,
},{
VoucherTitle: "title 6",
VoucherRedeemed: false,
},{
VoucherTitle: "title 9",
VoucherRedeemed: true,
}
How do I sort the viewModel.voucher based on the checkbox value, after mapping:
viewModel.voucher = ko.mapping.fromJS(voucherData.voucher)
I've had a look at sorting observable arrays, but did not manage to tie up to the mapping scenario for checkbox value sorting. (.html)
Any example of how to sort an array after ko.mapping.fromJS will be appreciated!
Data example, where VoucherRedeemed
is a checkbox
value:
{
VoucherTitle: "title 2",
VoucherRedeemed: false,
},{
VoucherTitle: "title 4",
VoucherRedeemed: true,
},{
VoucherTitle: "title 6",
VoucherRedeemed: false,
},{
VoucherTitle: "title 9",
VoucherRedeemed: true,
}
How do I sort the viewModel.voucher based on the checkbox value, after mapping:
viewModel.voucher = ko.mapping.fromJS(voucherData.voucher)
I've had a look at sorting observable arrays, but did not manage to tie up to the mapping scenario for checkbox value sorting. (http://knockoutjs./documentation/observableArrays.html)
Any example of how to sort an array after ko.mapping.fromJS will be appreciated!
Share Improve this question edited Jan 27, 2012 at 6:18 bcm asked Jan 27, 2012 at 4:51 bcmbcm 5,50010 gold badges60 silver badges92 bronze badges2 Answers
Reset to default 6You can sort once you have populated the view model.
Have a look at the fiddle I have put together here Knockout Sort Example
You need to call the sort method on the observable passing in a function to sort on the property you want.
I figured.
Sort the voucherData before mapping it into the viewModel. Once it is in the viewModel, not sure if it is possible or easy to do any sorting.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744985920a4604606.html
评论列表(0条)