在react.js中添加锚标记中的参数

时间:2015-09-18 14:07:58

标签: javascript reactjs

我正在尝试在我的锚标记的href属性中添加用户名。 我的代码是,

var Name = React.createClass({

    render: function() {
        return (
            <div>
                <a href="www.example.com/"+ { this.props.username} +"" className="post-title">{this.props.name}</a><br />
            </div>
        );
    }

});

但是,我在该href属性附近发出错误undefined token +。我认为这是由于我试图在render方法中添加它。那么,还有其他方法吗?

谢谢..

2 个答案:

答案 0 :(得分:4)

删除+。它应该是:

<a href={"www.example.com/" + this.props.username} ...

答案 1 :(得分:0)

另一种方法是:

www.example.com / $ {this.props.username1} ...

相关问题