我想在使用Kotlin和Vaadin 14:的网格中提供一个下载按钮
grid.addComponentColumn{item ->
val button = Button(item.plandatei)
val resource = StreamResource(item.plandatei) { this.getStream(item.plandatei) }
val anchor = Anchor(resource)
anchor.getElement().setAttribute("download", true)
anchor.getElement().appendChild(button.getElement())
return@addComponentColumn anchor
}
fun getStream(filename: String): InputStream {
val file = File(filename)
file.readBytes()
}
我收到这个错误消息:
Overload resolution ambiguity. All these functions match.
public constructor StreamResource(name: String!, factory: InputStreamFactory!) defined in
com.vaadin.flow.server.StreamResource
public constructor StreamResource(name: String!, writer: StreamResourceWriter!) defined in
com.vaadin.flow.server.StreamResource
如何将getStream函数中的InputStream转换为InputStreamFactory?还是别的什么?
您需要帮助Kotlin编译器。请尝试
val resource = StreamResource(item.plandatei, InputStreamFactory { this.getStream(item.plandatei) } )