Using Underscore Template with Knockout using interpolate due to asp.net

前端 未结 3 1912
闹比i
闹比i 2020-12-20 00:53

Issue

I need to use the underscore template instead of the default KnockoutJS template engine due to performance. However, since I\'m in an asp.net environment th

3条回答
  •  悲哀的现实
    2020-12-20 01:37

    You're asking how to change Underscore's delimiter characters? This SO answer seems to have the right answer. Basically, you can define your own regex for nesting data:

    _.template("hello ", {"name": "Mike"}, {"interpolate": //g) ?>})
    

    A couple of side notes:

    You say you're using Underscore, instead of Knockout's native template engine, for performance reasons. As an avid Knockout user, this sounds fishy. Knockout's native template engine is very fast and ultimately tested far more than 3rd party engines plugged into Knockout. I've built numerous applications with KO and never had an issue with the template engine being too slow. Make sure you really need to use Underscore. For the vast majority of cases, Knockout's native template engine works perfectly fine.

    Secondly, are you aware of the Razor syntax? This wouldn't interfere with Underscore.

提交回复
热议问题