I am learning Backbone/Handlebars/Require. I have looked all over online and on SO - are there any tutorials or websites that you can direct me to that would provide helpful information for using using handlebars instead of underscore?
相关问题
- Backbone.js PushState routes .htaccess only workin
- Updating a LayoutView's Model
- RequireJS text plugin and variable concatenated st
- Disable Backbone.js hashes entirely, but keep push
- ember component based on model type
相关文章
- Get all models in backbone collection where attrib
- How to use autofocus with ember.js templates?
- How can I dynamically set a className for a Backbo
- How use require.js to load jQuery with noConflict
- Nesting Views within Views in backbone js
- Backbone-relational hasmany best practices
- JavaScript error: “is not a constructor”
- Marionette + i18n in templates
Using handlebars.js instead of underscore templating is pretty straightforward. Check out this example:
https://cdnjs.com/libraries/backbone.js/tutorials/what-is-a-view (scroll to the "Loading a Template" section)
Basically, the convention in backbone is to build your html in a render function. The use of templating engine is left completely up to you (which I like about Backbone). So you'd just change it to...
Since you're using require.js, you can make Handlebars a dependency at the top of your module. I'm pretty new to this, but it sounds like the learning to focus on would be Backbone.js patterns and require.js usage.
If you are using require.js you wont be able to use the current Handlebars file. I used the following Handlebars Plugin and it seems to be kept up to date with the current version. Just replace your Handlebars file with the plugin above if Handlebars is returning null in your module.
I would prefer to compile the template once (during initialize), that way you avoid to recompile the template with every render. Also, you need to pass the model to the compilated template in order to generate the HTML: