如何在 Durandal 视图中 运行 脚本

How to run scripts in Durandal View

我有一个 Durandal 应用程序。

在其中一个页面上,我需要使用一些我不想修改的现有 javascript。

但是,如果我在 view.html 中使用这样的东西:

<script>alert("test");</script>

未触发警报。

通常这样的代码会进入 ViewModel。但是,在这种情况下,我想使用 Sound Recorder 并且有许多脚本构成了它,我想按原样使用它们。

换句话说,我希望 view.html 像普通 html 页面一样工作。

当我修改路由器以使用 *.html 时,它会抛出一个错误。

{ route: 'recorder', moduleId: 'views/recorder.html', nav: true }

有办法解决吗?

采纳 OP 的建议并发布我的评论作为答案:

根据 Rob Eiserberg(Durandal 的作者)的说法,不要做 this. The reason being is that all script tags within the view are stripped. I'm sure this is done as a security precaution. Additionally, you could implement the solution recommended here