Insert script tag in Durandal

一笑奈何 提交于 2019-12-12 15:29:40

问题


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?

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.

Thanks

Nicolas


回答1:


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>

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;
});


来源:https://stackoverflow.com/questions/16398383/insert-script-tag-in-durandal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!