gpt4 book ai didi

javascript - 在 className react.js 中调用函数

转载 作者:可可西里 更新时间:2023-11-01 02:21:28 25 4
gpt4 key购买 nike

如何在这个示例中为 className 调用 getClass 函数?我写出来的方式似乎没有调用 getClass

var CreateList = React.createClass({
getClass: function() {
//some code to return className
},
render: function() {
return(
<div className{this.getClass}>Example</div>
);
}
});

最佳答案

您引用的是 getClass() 函数的实例,而不是调用该函数。尝试像这样调整它:

render: function() {
return(
<div className={this.getClass()}>Example</div>
);
}

关于javascript - 在 className react.js 中调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34011322/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com