我有一个对象数组,我将其输出到一种形式的输入。这些输入需要更新,呈现的值才能显示更改。我能够控制键和新值,但是我收到的错误是metafields.map不是一个函数。 我的代码如下: class EditMetafields extends React.Component {
constructor(props) {
super(props);
this.state = { metafields: [] }
}
componentDidMount() {
// retrieving data from the db to populate metafie
interface list {
name: string,
id: number,
marks: number
} 组件状态: {
listOfStudents: list[],
} 现在,在一些事件中,修改了具有给定姓名和以下处理函数的学生的分数,以下代码不起作用 currentList = this.state.listOfStudents;
//find the list object with the given name
listToModify = currentList.map(item, ....=> item.name === event.name);
// upd
我有一个名为this.state.devices的状态,它是一个device对象数组。
假设我有一个功能
updateSomething: function (device) {
var devices = this.state.devices;
var index = devices.map(function(d){
return d.id;
}).indexOf(device.id);
if (index !== -1) {
// do some stuff with device
devices[index]
当阅读时,我偶然发现了一个代码片段,当用户在TODO列表中检查完成的任务时,这个函数就会被调用:
markAsCompleted = id => {
// Finding the task by id...
const foundTask = this.state.items.find(task => task.id === id);
// Updating the completed status...
foundTask.completed = true;
// Updating the state with the new up
我有两门课:
儿童Class)mySpreadsheet (家长班) Row ()
我试着做这样的事情:
行:
class Row extends React.Component {
constructor(props, ref) {
super(props);
this.state = { selectedFile: null}
this.handleUpload = this.handleUpload.bind(this);
}
//This handleUpload is being called by the parent class of this
我对更改对象数组中的属性有疑问。为了更好地理解,我将在下面发布我的代码。首先,我有一个包含两个数组对象数组,第一个数组包含名为" First“的属性,第二个数组包含"last”属性。当我单击该函数时,它会将特定的名称作为字符串传递,比如first或last。在此之后,我必须遍历对象数组并更改与属性名称(tempFirst,tempLast)匹配的值。我只是在onHandle函数中声明,但在我的实际项目中,我正在传递参数。
例如: if (first === first)更改该属性的值。
import logo from './logo.svg';
impo
我尝试了什么,我的问题,我开始创建一个外部函数,并通过onClick运行它.这在一定程度上是因为它在点击时发送警报。请参阅服务页面 on 。单击小图像以触发显示if语句、state.active:value和state.id:value的警报。所以我知道正确的陈述被触发了。
我的问题是,我一直让state[i].setState is not a function返回,而不是按预期设置状态。
我已经将函数在内部和外部放置到class Player,并且它返回了相同的问题。
我按照建议的将函数转换为内部箭头函数。
我把它转换成一个const changeActiveField = () =>