首页 > OS X 从 Finder 复制文件, 粘贴到 Chrome 里, 事件当中有两个内容

OS X 从 Finder 复制文件, 粘贴到 Chrome 里, 事件当中有两个内容

处理文件粘贴上传的时候, 粘贴了一个文件, 结果事件打印出来除了文件, 还有个 string,

onPaste: (event) ->
  clipboardData = event.clipboardData
  acceptedFiles = @props.acceptedFiles.split(',')
  .map (extension) -> extension.slice(1)

  Array::forEach.call clipboardData.types, (type, i) =>
    console.log type, i, clipboardData.items[i]
    if type is 'Files'
      matchFile = acceptedFiles.some (extension) ->
        fileType = clipboardData.items[i].type
        fileType.indexOf(extension) >= 0
      if matchFile
        file = clipboardData.items[i].getAsFile()
        console.log 'file found', file
        return
    console.log 'not found'

这个行为有点奇怪, 有遇到过的同学吗?

【热门文章】
【热门文章】