2014-10-30 4 views
0

CANJS 문서를 통해 can.List()에 정렬 함수를 구현하려고했습니다.CANJS sort() 함수 사용 방법

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 

콘솔 (브라우저)에서 실행하려고했을 때. 그것은 "Uncaught TypeError : undefined가 함수가 아닙니다"라고 말합니다. 왜? 내가 여기서 뭔가를 놓치고 있니?

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

답변

2

목록을 정렬하려면 기본 canjs와 함께 can.list.sort 플러그인이 필요합니다. http://canjs.com/release/latest/can.list.sort.js

+1

감사합니다 :) 플러그인을 콘솔에 추가하려면 다음을 추가하십시오. var script = document.createElement ('script'); script.src = 'http://canjs.com/release/latest/can.list.sort.js'; document.getElementsByTagName ('head') [0] .appendChild (script); – Jry9972

+0

또는 jQuery가 이미로드 된 경우 :''$ ('head'). append ("") " –

1

당신이로드 할 수 있는지 확인해야 브라우저 콘솔에서이 작업을 실행하는 경우. 콘솔에 can을 입력하여 점검 할 수 있습니다. 함수 객체 등을 반환해야합니다. 그렇다면 거기에있는 경우 직접 작성한 경우 List가 Can 버전에 포함되어 있는지 확인해야합니다.