function init() {
var DATAJson=JSON.parse(DATA);
var sort=DATAJson.sort(function(a,b){
return a.status>b.status?-1:1
});
//console.log(sort);
String.prototype.temp = function(obj) { //替换$$里面的内容
return this.replace(/$w+$/gi, function(matchs) { //
var returns = obj[matchs.replace(/$/g, "")]; //匹配json中每个以$开头的
return (returns + "") == "undefined"? "": returns;
});
};
var htmlList = ''
, htmlTemp = $("ul").html();
//console.log(htmlTemp.temp(DATAJson));
DATAJson.forEach(function(item) {
htmlList += htmlTemp.temp(item);
});
$("ul").html(htmlList);
$("#DONE").empty().html("未完成");
}
网上抄的模板,注意正则!!!
var DATAJson=JSON.parse(DATA);
var sort=DATAJson.sort(function(a,b){
return a.status>b.status?-1:1
});
//console.log(sort);
String.prototype.temp = function(obj) { //替换$$里面的内容
return this.replace(/$w+$/gi, function(matchs) {
var returns = obj[matchs.replace(/$/g, "")]; //匹配json中每个以$开头的
return (returns + "") == "undefined"? "": returns;
});
};
var htmlList = ''
, htmlTemp = $("ul").html();
//console.log(htmlTemp.temp(DATAJson));
DATAJson.forEach(function(item) {
htmlList += htmlTemp.temp(item);
});
$("ul").html(htmlList);
$("#DONE").empty().html("未完成");
}