传递给onMove方法的未定义参数

时间:2016-04-21 11:10:26

标签: javascript reactjs

我使用react-absolute-grid(https://github.com/jrowny/react-absolute-grid)来显示一组图像。

我有以下onMove方法:

  onMove: function(source, target) {
    var sampleItems = this.state.items
    source = _.find(sampleItems, {key: parseInt(source, 10)});
    target = _.find(sampleItems, {key: parseInt(target, 10)});

    var targetSort = target.sort;

    //CAREFUL, For maximum performance we must maintain the array's order, but change sort
    sampleItems.forEach(function(item){
      //Decrement sorts between positions when target is greater
      if(target.sort > source.sort && (item.sort <= target.sort && item.sort > source.sort)){
        item.sort --;
      //Incremenet sorts between positions when source is greator
      }else if(item.sort >= target.sort && item.sort < source.sort){
        item.sort ++;
      }
    });

    source.sort = targetSort;

    this.setState({items: sampleItems})
  },

我从这里的演示中复制粘贴的内容:https://github.com/jrowny/react-absolute-grid/blob/733b3f752e2b9af7314029bb64fb883f2a28a6a8/demo.js

另外,我正在显示这样的网格:

<AbsoluteGrid
  items={this.state.countries}
  displayObject={<DisplayObject/>}
  onMove={onMoveDebounced}
  dragEnabled={true}
  responsive={true}
  verticalMargin={42}
  itemWidth={250}
  itemHeight={250}
  filteredProp={'name'}
/>

问题在于,每当我尝试移动图片时,我都会收到此错误:

Uncaught TypeError: Cannot read property 'sort' of undefined

这是因为此处传递的两个参数onMove: function(source, target) {都是undefined

为什么会这样? 如何确保参数正确传递?

0 个答案:

没有答案