jquery.tablesorter addParser for “26 Jul”日期格式
我想对如下所示的日期进行排序: 7 月 26 日
这是我添加解析器的尝试:
var lMonthNames = {};
lMonthNames["Jan"] = "01";
lMonthNames["Feb"] = "02";
lMonthNames["Mar"] = "03";
lMonthNames["Apr"] = "04";
lMonthNames["May"] = "05";
lMonthNames["Jun"] = "06";
lMonthNames["Jul"] = "07";
lMonthNames["Aug"] = "08";
lMonthNames["Sep"] = "09";
lMonthNames["Oct"] = "10";
lMonthNames["Nov"] = "11";
lMonthNames["Dec"] = "12";
ts.addParser({
id: 'monthDay',
is: function(s) {
return false;
},
format: function(s) {
if (s.length > 0) {
var date = s.match(/^(\d{1,2})[ ](\w{3})[ ](\d{4})$/);
var m = lMonthNames[date[2]];
var d = String(date[1]);
if (d.length == 1) {d = "0" + d;}
return '' + m + d;
} else {
return '';
}
},
type: 'numeric'
});
但是 firebug 控制台告诉我日期为空 var m = lMonthNames[日期[2]]; 你能说出为什么它没有价值吗?
I want to sort dates which look like this:
26 Jul
This is my attempt at adding a parser:
var lMonthNames = {};
lMonthNames["Jan"] = "01";
lMonthNames["Feb"] = "02";
lMonthNames["Mar"] = "03";
lMonthNames["Apr"] = "04";
lMonthNames["May"] = "05";
lMonthNames["Jun"] = "06";
lMonthNames["Jul"] = "07";
lMonthNames["Aug"] = "08";
lMonthNames["Sep"] = "09";
lMonthNames["Oct"] = "10";
lMonthNames["Nov"] = "11";
lMonthNames["Dec"] = "12";
ts.addParser({
id: 'monthDay',
is: function(s) {
return false;
},
format: function(s) {
if (s.length > 0) {
var date = s.match(/^(\d{1,2})[ ](\w{3})[ ](\d{4})$/);
var m = lMonthNames[date[2]];
var d = String(date[1]);
if (d.length == 1) {d = "0" + d;}
return '' + m + d;
} else {
return '';
}
},
type: 'numeric'
});
But the firebug console tells me date is null for
var m = lMonthNames[date[2]];
Can you pick why it doesn't have a value?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为您拥有的正则表达式与您提供的数据不匹配。
您的匹配类似于:
26 Jul 2010
,而不是类似于26 Jul
。要么更改表中的数据,要么将正则表达式更改为:
Because the regular expression you have doesn't match the data you are giving it.
Your's matches things like:
26 Jul 2010
and not things like26 Jul
.Either change the data in the table, or change the regular expression to be: