未捕获(承诺)类型错误:无法在 eval 读取未定义的属性“setState”

时间:2021-05-26 11:53:50

标签: javascript reactjs react-router

使用库Intercat.js,我想做一个拖放应用程序女巫我可以通过将它们拖到新列来将一些卡片从一种状态更改为另一种状态,问题是当我将卡片放入新列时,状态不会改变,我在 this.setState 中有错误,“this”在拖放函数中是未定义的,但是当我重新启动页面时,状态会根据我的需要改变。 这是我的代码

componentDidMount() {
    …
    interact('.dropzone').dropzone({
      accept: '#yes-drop',
      overlap: 0.10,

      // listen for drop related events:
      ondropactivate(event) {
        event.target.classList.add('dropActive');
      },
      ondragenter(event) {
        currentActionId = event.relatedTarget.firstChild.id;
        nextActionTypeTitle = event.currentTarget.innerText;
        console.log('Dragged in');
      },
      ondragleave(event) {
        console.log('Dragged out');
      },
      // eslint-disable-next-line no-unused-vars
      ondrop(event) {
        console.log('droppped');
      },
      // eslint-disable-next-line no-unused-vars
      ondropdeactivate(event) {
        // eslint-disable-next-line array-callback-return
        actionTypesTab.map(row => {
          if ((row.typeName + ' ' + row.percentage + ' %') === nextActionTypeTitle) {
            newCommercialActionType = { _id: row.actionTypeId };
            // eslint-disable-next-line array-callback-return
            commercialActionsTab.map(line => {
              if (line._id === currentActionId) {
                // eslint-disable-next-line array-callback-return
                line.contacts.map(column => { column.checked = true; });
                line.contactsIds = line.contacts;
                line.commercialActionId = line._id;
                line.commercialActionType = newCommercialActionType;
                CommercialActionService.updateCommercialAction(line).then(result => {
                  newData = result.data.payload;
                  this.setState({ commercialActions: newData }); <----------------- The problem (this is undefined)
                });
              }
            });
         }
        });
      }
    });

这里已经定义了这个函数我叫他帮我处理一下

enter image description here

0 个答案:

没有答案