Scala.js,wavesurfer.js 的类型外观
Scala.js, typed facade for wavesurfer.js
我正在为 wavesurfer.js library. I have read the official docs and questions 实现外观。这应该是一件容易的事,但是我遇到了一些问题。我目前拥有的:
@js.native
trait WaveSurferOpts extends js.Object {
val container: String = js.native
val waveColor: String = js.native
val progressColor: String = js.native
}
object WaveSurferOpts {
def apply(container: String, waveColor: String, progressColor: String): WaveSurferOpts = {
js.Dynamic.literal(
container = container,
waveColor = waveColor,
progressColor = progressColor
).asInstanceOf[WaveSurferOpts]
}
}
@js.native
trait WaveSurfer extends js.Object {
def load(url: String): js.Any = js.native
}
@js.native
object WaveSurfer extends js.Object {
def create(options: WaveSurferOpts): WaveSurfer = js.native
}
它编译得很好,但是 运行
val wso = WaveSurferOpts("#waveform", "violet", "purple")
val ws = WaveSurfer.create(wso)
ws.load("audio.wav")
我明白了
VM4626:27 Error: Container element not found
at Object.WaveSurfer.init (lingvodoc2-frontend-jsdeps.js:47468)
at Object.WaveSurfer.create (lingvodoc2-frontend-jsdeps.js:47468)
at
似乎选项(基本上,唯一需要的参数是container
)没有正确传递。我的代码有什么问题?
当给定容器标识符的 DOM 中没有元素时触发 "Container element not found",而不是当容器 属性 本身不存在时触发。确保确实存在一个 ID 为#waveform.
的 DOM 元素
我正在为 wavesurfer.js library. I have read the official docs and
@js.native
trait WaveSurferOpts extends js.Object {
val container: String = js.native
val waveColor: String = js.native
val progressColor: String = js.native
}
object WaveSurferOpts {
def apply(container: String, waveColor: String, progressColor: String): WaveSurferOpts = {
js.Dynamic.literal(
container = container,
waveColor = waveColor,
progressColor = progressColor
).asInstanceOf[WaveSurferOpts]
}
}
@js.native
trait WaveSurfer extends js.Object {
def load(url: String): js.Any = js.native
}
@js.native
object WaveSurfer extends js.Object {
def create(options: WaveSurferOpts): WaveSurfer = js.native
}
它编译得很好,但是 运行
val wso = WaveSurferOpts("#waveform", "violet", "purple")
val ws = WaveSurfer.create(wso)
ws.load("audio.wav")
我明白了
VM4626:27 Error: Container element not found
at Object.WaveSurfer.init (lingvodoc2-frontend-jsdeps.js:47468)
at Object.WaveSurfer.create (lingvodoc2-frontend-jsdeps.js:47468)
at
似乎选项(基本上,唯一需要的参数是container
)没有正确传递。我的代码有什么问题?
当给定容器标识符的 DOM 中没有元素时触发 "Container element not found",而不是当容器 属性 本身不存在时触发。确保确实存在一个 ID 为#waveform.
的 DOM 元素