如果由于某种原因必须使用其中包含这些
u....代码而不是真实字母的字符串,请将其转换为数字,然后使用String.fromCharCode()将这些数字转换为真实字母。我们可以为此使用正则表达式替换为处理函数:
function convertUnipre(input) { return input.replace(/\u(wwww)/g,function(a,b) { var charpre = parseInt(b,16); return String.fromCharCode(charpre); });}var Hello = React.createClass({ getInitialState: function() { return { name: convertUnipre(this.props.name) }; }, render: function() { return <div>Hello {this.state.name}</div>; }});React.render( <Hello name="Informaciu00f3n" />, document.getElementById('container'));小提琴:https :
//jsfiddle.net/dddf7o70/4/



