UIChatBox模块,前端显示emoji
//前端读取表情文件
var url = "../image/emotion/emotion.json";
var request = new XMLHttpRequest();
request.open("get", url);
request.send(null);
request.onload = function () {
emotionjson = JSON.parse(request.responseText);
}
//显示emoji表情
function showemoji(str){
var regex = /\[(.+?)\]/g; // 匹配[]中括号
var arr = str.match(regex);
if(arr == null) return str;
for(var i = 0; i < arr.length; i++) {
for(var j=0;j<emotionjson.length;j++){
if(emotionjson[j].text == arr[i]){
str = str.replace(arr[i],"<img class='comment-emoji-img' src='../image/emotion/"+emotionjson[j].name+".png' alt=''>");
}
}
}
return str
}
doT.js渲染
var appendText = $api.byId('container');
var tempFn = doT.template($api.byId('template').innerHTML);
var resultText = tempFn(ret);
$api.html(appendText,resultText);