好的,我有一个元素设置来接收文件丢弃事件,但当我查看event.dataTransfer
时,它是空白的。我还没有开始学习拖放式HTML5 API,但仍然有点模糊。我正在my site处理它。如果您不介意在我的代码中查看并查看正在进行的操作,那么我们将非常感激。正在记录整个event
对象。
答案 0 :(得分:100)
它工作正常,这只是控制台的一个错误。
function onDrop(event) {
event.preventDefault();
console.log(event.dataTransfer.files[0]);
}
答案 1 :(得分:2)
另请查看此错误/行为:HTML5 drop event doesn't work unless dragover is handled
基本上,您需要处理悬停/拖动并指定dropEffect
答案 2 :(得分:0)
我在以下位置找到了所需的东西
// We are trying to get our pickers to sync their provided type when you pull to refresh. But the implementation of refresh(:, completion:) that we added doesn’t get called.
import Foundation
protocol PickerItemProvider: class {
associatedtype PickerType
func findItem(by identifier: NSNumber) -> PickerType?
func itemAt(_ indexPath: IndexPath) -> PickerType?
func refresh(_ sender: Any, completion: (() -> Void)?)
}
extension PickerItemProvider {
func findItem(by identifier: NSNumber) -> PickerType? {
return nil
}
public func refresh(_ sender: Any, completion: (() -> Void)?) {
print("the default refresh implementation")
}
}
public class PickerSectionProvider<ProvidedType: Equatable> : PickerItemProvider {
func itemAt(_ indexPath: IndexPath) -> ProvidedType? {
return nil
}
}
extension PickerItemProvider where PickerType: Equatable & SyncableEntity {
func refresh(_ sender: Any, completion: (() -> Void)?) {
print("we’re trying to have this implementation called instead of the above implementation of refresh")
PickerType.startSync()
}
}
protocol SyncableEntity {
static func startSync()
}
extension SyncableEntity {
static func startSync() {
}
}
class ObservationType: Equatable, SyncableEntity {
}
func ==(lhs: ObservationType, rhs: ObservationType) -> Bool {
return false
}
class GenericPickerViewController<PickerType: Equatable, ItemProvider: PickerItemProvider> where ItemProvider.PickerType == PickerType {
var itemProvider: ItemProvider?
init() {
}
func foo() {
// Why doesn’t the implementation of refresh(:,completion:) we added get called here?
itemProvider?.refresh("dummy sender") {
}
}
}
class PopupPickerRow<T: Equatable, ItemProvider: PickerItemProvider> where ItemProvider.PickerType == T {
var pickerController = GenericPickerViewController<T, ItemProvider>()
}
let pickerSectionProvider = PickerSectionProvider<ObservationType>()
let row = PopupPickerRow<ObservationType, PickerSectionProvider<ObservationType>>()
row.pickerController.itemProvider = pickerSectionProvider
row.pickerController.foo()
答案 3 :(得分:-1)
关于 Esailja 的回答还有一件事,我正在从垃圾箱传输文件,当我从本地目录尝试时,它工作正常。