【发布时间】:2016-07-07 04:37:30
【问题描述】:
我正在为wavesurfer.js 库实现一个外观。我已经阅读了官方的docs 和these 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)没有正确传递。我的代码有什么问题?
【问题讨论】:
-
"Container element not found"被触发 when there is no element in the DOM for the givencontaineridentifier,而不是当container属性本身不存在时。确保确实存在一个 DOM 元素,其id是#waveform。 -
哦,我必须自己检查一下。 JS经验不多。谢谢。