简体   繁体   中英

Spacebars retrieving template from javascript

I've currently migrated my meteor to 0.8, but i'm having some headache migrating from handlebars to spacebars.

Currently in my javascript function, I retrieve a template and put it inside a leaflet popup.

var marker = new L.Marker(...)
.addTo(map).bindPopup(Template.PopupForm({
  data: data
}));

What is the equivalent for this in spacebars ?

Thank you

Template.name no longer returns just HTML content, it returns a Template object that needs to be rendered and inserted via Meteor's methods. Since you need to pass a ready DOM element to Leaflet's method, you need to create an intermediate div. First you'll render your template to that div, then you can pass it to Leaflet's bindPopup method.

Code:

var div = document.createElement('div');

UI.insert(UI.renderWithData(Template.PopupForm, {
  data: data,
}), div);

L.Marker(...).addTo(map).bindPopup(div);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM