- Creator 版本:2.0.9
文本内容: 
实际显示:
这段富文本文字是由服务端传过来的,在服务端数据无法改变的情况下,我要怎么处理才能正确显示呢??大佬们帮忙看看
文本内容: 
实际显示:
这段富文本文字是由服务端传过来的,在服务端数据无法改变的情况下,我要怎么处理才能正确显示呢??大佬们帮忙看看
var text = '1>传说道具几率'; // 服务器传过来的文字
text = text.replace(/(\d+\s?)>/g, '$1>'); // Escape
node.string = text; // 赋值
用正则表达式可破(假设需要转换的大于号只出现于数字后)
突然发现 <size=28> 也会被捕获
这种xml标签和大小于号混用比较麻烦,长远考虑还是和后端商量一下大小于号用转义文字比较好
嗯,但实际情况可能还要复杂一些,提出这个问题,主要是我看引擎底层代码逻辑好像不太合理,所以论坛上问问,希望有个比较完善的方案
贴上引擎底层代码吧:parse: function(htmlString) {
this._resultObjectArray = [];
this._stack = [];
var startIndex = 0;
var length = htmlString.length;
while (startIndex < length) {
var tagBeginIndex = htmlString.indexOf('<', startIndex);
if (tagBeginIndex < 0) {
this._stack.pop();
this._processResult(htmlString.substring(startIndex));
startIndex = length;
} else {
this._processResult(htmlString.substring(startIndex, tagBeginIndex));
var tagEndIndex = htmlString.indexOf('>', startIndex);
if (tagEndIndex === -1) {
// cc.error('The HTML tag is invalid!');
tagEndIndex = tagBeginIndex;
} else if (htmlString.charAt(tagBeginIndex + 1) === '\/'){
this._stack.pop();
} else {
this._addToStack(htmlString.substring(tagBeginIndex + 1, tagEndIndex));
}
startIndex = tagEndIndex + 1;
}
}
return this._resultObjectArray;
},