sortingcanjscanjs-list

How to use CANJS sort() function


I went through the CANJS documentation and tried to implement the sort function on can.List().

var list = new can.List([
    { name: 'Justin' },
    { name: 'Brian' },
    { name: 'Austin' },
    { name: 'Mihael' }])

list.comparator = 'name';
list.sort(); //- sorts the list by the name attribute

When i tried to run this on console(browser's). It is saying "Uncaught TypeError: undefined is not a function ". Why? Am i missing something here?

Reference: http://canjs.com/docs/can.List.prototype.sort.html


Solution

  • Sorting a list requires the can.list.sort plugin in addition to base canjs. You can download it from http://canjs.com/release/latest/can.list.sort.js