gpt4 book ai didi

javascript - 无法将符号值转换为字符串 - React AJAX 删除请求

转载 作者:行者123 更新时间:2023-11-28 05:27:48 25 4
gpt4 key购买 nike

我不明白为什么这会在控制台中抛出无法将符号值转换为字符串。我正在使用 React v15 和 jQuery v3。

enter image description here

这是我的 React 代码:

var CommentList = React.createClass({
handleDelete: function(comment) {
console.log(comment);
$.ajax({
url: this.props.url,
dataType: 'json',
type: 'DELETE',
data: comment,
contentType:'application/json',
dataType: 'text',
success: function(data) {
this.setState({ data: data });
}.bind(this),
error: function(xhr, status, err) {
this.setState({data: comments});
console.error(this.props.url, status, err.toString());
}.bind(this)
})
},
render: function() {
var commentNodes = this.props.data.map(comment => {
return(
<div key= { comment.id }>
<Comment author = { comment.author }>
{ comment.text }
</Comment>
<button onClick={this.handleDelete}>delete</button>
</div>
);
});
return (
<div className="commentList">
{commentNodes}
</div>
);
}
});

json 文件如下所示:

[
{
"id": 1388534400000,
"author": "Pete Hunt",
"text": "Hey there!"
},
{
"id": 1323434400000,
"author": "Ben Jerry",
"text": "I did a thing"
},
...
...
]

最佳答案

您没有将注释传递给handleDelete,它实际上是在接收点击事件。您可能只使用评论 ID 就可以逃脱惩罚。尝试一下列表渲染器:

<div key= {comment.id}>
<Comment author ={comment.author}>
{comment.text}
</Comment>
<button onClick={this.handleDelete.bind(this, comment)}>delete</button>
</div>

关于javascript - 无法将符号值转换为字符串 - React AJAX 删除请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39977046/

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