在Durandal中插入脚本标签 [英] Insert script tag in Durandal

查看:56
本文介绍了在Durandal中插入脚本标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对应该是一件容易的事情有点挣扎。
我想在div标签内插入脚本标签。问题在于Durandal(出于我仍然需要理解的原因)似乎忽略了这些标签。
这里已经描述了此问题,但是在那里提出的解决方案对我不起作用。
如何停止durandal / jquery

I am a bit struggling with what should be an easy task. I want to insert a script tag inside a div tag. The problem is that Durandal (for a reason that I still need to understand) seems to ignore those tags. This problem has been described here, but the solution proposed there does not work for me. how to stop durandal / jquery stripping out script tags from views?

难道没有一种简单的方法告诉Durandal请解释我的脚本标签吗?
这变得非常令人沮丧,除了上述问题,我在网上找不到关于此的任何内容。

Isn't there a simple way to tell Durandal to please interpret my script tags? This is becoming very frustrating, and besides the above question, I couldn't find anything on the web about this.

谢谢

尼古拉斯(Nicolas)

Nicolas

推荐答案

好的,这就是我要做的事情。
在父标记中,我使用了这样的组合绑定:

Ok, here's what I do to get this to work. Inside the parent tag, I use a compose binding like so:

<td>
     <!-- ko compose: { view: 'views/homearea', model: 'viewmodels/homearea' } -->
     <!-- /ko-->
</td>

在我看来,我有这样的东西:

Inside my view, I have something like this:

<div id="homearea" style="height: 400px; width: 400px;">    
</div>

在模型内部,在viewAttached方法中,我可以放置自定义的javascript。

And inside the model, in the viewAttached method, I can put my custom javascript.

define(function () {

    var viewAttached = function () {
        $('#homearea').myFunction();
    };

    var vm = {
        viewAttached: viewAttached
    };
    return vm;
});

这篇关于在Durandal中插入脚本标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆