我经历了CANJS文档,并试图在can.List()上实现sort函数。如何使用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
下载它谢谢:)添加插件到控制台,只需添加: var script = document.createElement('script'); script.src ='http://canjs.com/release/latest/can.list.sort.js'; document.getElementsByTagName('head')[0] .appendChild(script); – Jry9972 2014-11-05 06:39:34
或者您已经加载了jQuery:'''$('head')。append(“”)' '' – 2014-11-06 00:07:24