I am new to ractive.js and want to integrate it with backbone.js. I found a backbone adapter for ractive howevere didn't found a sample which will show to use it effectively. Need a sample that explain how to use ractive.js as a view component in backbone.js
相关问题
- Backbone.js PushState routes .htaccess only workin
- Updating a LayoutView's Model
- Disable Backbone.js hashes entirely, but keep push
- Is there an easy way to distribute a Flask server
- React + Backbone, Target container is not a DOM el
相关文章
- Get all models in backbone collection where attrib
- How can I dynamically set a className for a Backbo
- Nesting Views within Views in backbone js
- Backbone-relational hasmany best practices
- JavaScript error: “is not a constructor”
- Marionette + i18n in templates
- Rendering reCAPTCHA v2.0 widget within Backbone vi
- Backbone.js PUT/DELETE problems with Codeigniter R
Since the official demo seems to be down, I was able to put together a simple demo based on the rest of documentation.
Basically include ractive and ractive adapter for backbone after backbone and dependencies, then in your view's render method initialize a new ractive view passing it the backbone view's element, template and model data as
el
,template
anddata
respectively as shown in below example.For one way bindings, use the model getter method like
{{model.get('prop')}}
and for two way bindings directly refer the property like {{model.attributes.name
}}Also, to avoid possibility of memory leak, override backbone view's
remove
method and have it destroy it's ractive view before removing itself.Hope the comment explains the process:
I find it a bit strange that we have to do
user.get('name')
in the template for one way binding anduser.attributes.name
for two way binding.It could've been abstracted away in the Backbone adapter like
user.name
likes rivets does.