小程序rich-text中不识别换行符

2,235 阅读1分钟

有些后段接口返回的字符串中带有但是展示在页面中未进行换行。这种需要手动处理。

var handleDescWithBr = function(str) {  
    if (str.indexOf('\r\n') !== -1) {    
        return str.replace(getRegExp('\r\n', 'g'), '<br/>');  
    }  
    if(str.indexOf('\r') !== -1) {   
        return str.replace(getRegExp('\r', 'g'), '<br/>');  
    }  
    if(str.indexOf('\n') !== -1) {    
       return str.replace(getRegExp('\n', 'g'), '<br/>');  
    }  
    return str;
}