Does Handlebars require jQuery

ぐ巨炮叔叔 提交于 2019-12-13 02:15:20

问题


I'm trying to build a Handlebars app using only JavaScript. I've noticed in there documentation, they initialize using:

var source   = $("#entry-template").html();

Is this step required or is there a way around it using only native Javascript?


回答1:


No, it doesn't require jQuery.

Only reason why people prefer jQuery is because of ease of use with which jQuery perform various operations. It saves lots of time & additional effort.

Using handlebars with plain javscript will require some extra effort. If you have enough time then you should try out things with plain JavaScript.

Below given links might be of some help to understand things better -

http://code.tutsplus.com/tutorials/handlebarsjs-a-behind-the-scenes-look--net-32678

http://www.raymondcamden.com/2012/04/19/Demo-of-Handlebars-and-why-you-should-consider-a-templating-engine




回答2:


No. If you read the example further you would see they are only using jQuery to get the HTML content of an element. This is something that could have been done in vanilla JS. Any code that follows is not jQuery. The following is the same example sans jQuery. As you can see the way Handlebars is written is unaffected.

var source   = document.getElementById("entry-template").innerHTML;
var template = Handlebars.compile(source);


来源:https://stackoverflow.com/questions/30950150/does-handlebars-require-jquery

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