// 格式化字符串
function formateString(str, data) {
return str.replace(/\{#{(\W+)}#\}/g, function (match, key) {
return typeof data[key] === undefined ? '' : data[key];
})
}
var PersonNav = function (data) {
// 导航样式模板
this.item = '<span id={#idname#} class="personMenu" onclick="personsMenu.go(this)">{#name#}</span>';
this.html = '';
for (var i = 0, len = data.length; i < len; i++){
this.html += formateString(this.item,data[i]);
}
return this.html;
}
JS设计模式16.8 创建多类导航