how to stop durandal / jquery stripping out script tags from views?

前端 未结 3 1515
南旧
南旧 2020-12-19 14:58

I know there are better patterns but in this case there\'s some legacy code that we\'d like to move to a view. This html has a



        
3条回答
  •  粉色の甜心
    2020-12-19 16:00

    If it's not already, you could wrap whatever is going on inside the script in a function (let's call it doBindings) and then embed the script in your index.html file (or equivalent), alongside Knockout, JQuery etc.

    Then, in whatever view you need to get that code running in, add a viewAttached method to the view model and make the call to doBindings:

    activate: function() {
       ...
    }
    viewAttached: function() {
       doBindings();
    }
    

    That will invoke the function when the view is loaded and the DOM is accessible.

    Solution here: Insert script tag in Durandal, but an answer here would have saved me some additional searching, so added here too.

提交回复
热议问题