handlebars.js

Ember.js - “Cannot perform operations on a Metamorph that is not in the DOM” caused by template

让人想犯罪 __ 提交于 2019-12-04 19:49:38
问题 I've been having an issue with Ember.js throwing the error: Uncaught Error: Cannot perform operations on a Metamorph that is not in the DOM. I found these two SO questions, both of which involve direct manipulation of the DOM, which is not the case in my app. Searching for the error message also returns numerous Github issues related to the same type of direct DOM manipulation. 回答1: I was at a loss until I happened upon this issue on Github from a search entirely unrelated with the error

Node.js - res.render won't update view on browser

為{幸葍}努か 提交于 2019-12-04 19:49:12
I'm using express and handlebars to build a web app. When I attempt to render a new template, however, the browser doesn't get updated at all. The console output contains the rendered html, but the page on screen stays the same. My code: router.post('/login', function(req, res) { User.findByUsername(req.body.username, function(err, user) { if(err === null) { req.session.username = req.body.username; req.currentUser = user; console.log("rendering"); //prints res.render('x.handlebars', {currentUser : req.session.username}); } else utils.sendErrResponse(res, 403, 'Username invalid'); }); }); res

Rendering templates within helpers in handlebars

混江龙づ霸主 提交于 2019-12-04 19:34:40
问题 Hey guys! Because there seem to be no answer on this: Passing variables through handlebars partial yet, I'm currently working on a little workaround to get this work. So, the idea is to register a helper function which renders a specific template with possible values. A bit code makes it better to understand. This is how a I'd invoke my helper: <div> {{myHelper}} </div> This helper is registered with this little code: hbs.registerHelper(name, function (args) { args = args || {}; var template

Difference between .create() and .createWithMixins() in ember

自作多情 提交于 2019-12-04 19:32:53
问题 What is the difference between .create() and .createWithMixins() ? I am not able to find any documentation regarding this. When I create a view instance using .create() and call this._super() in the didInsertElement method then, following error is thrown: Ember.Object.create no longer supports defining methods that call _super. But, when I replace .create() with .createWithMixins() everything works fine. Here is the code and the sample js fiddle : App.SampleView = Ember.View.create({

Grouping members of a collection by category in a Meteor template

故事扮演 提交于 2019-12-04 18:45:20
I have a single Workouts collection, each object having a category and a name . At the HTML layer, I'm creating a category header, then displaying a list of workouts beneath. I have it working, but there's no way I'm doing it the meteor and/or handlebars way. Think I'm struggling with understanding the context of this , as well as how to pass data into a template. Here are my template functions: Template.categories.getCategories = -> workouts = Workouts.find().fetch() categories = _.map workouts, (workout) -> workout.category _.uniq categories Template.workouts.getWorkouts = -> Workouts.find

how to pass parameters to Handlebars helper? What's the difference between options.hash & options.data

痞子三分冷 提交于 2019-12-04 17:44:18
问题 Here's a typical Handlebars helper: Ember.Handlebars.helper 'myHelper', (value, options) -> ... According to this protip you can pass hash to Handlebars helpers. I looked over the source and found out that it provides both options.hash and options.data . I'm a bit confused as this wouldn't work as expected: {{#with controllers.currentCardCategory}} {{#each property in cardProperties}} <td class="td">{{cardProperty this property=property.symbol}}</td> {{/each}} {{/with}} this is the current

How can I dynamically set the `selected` attribute on an `<option>` tag?

只谈情不闲聊 提交于 2019-12-04 17:18:37
The Ember guide on binding data attributes says that "If you use data binding with a Boolean value, it will add or remove the specified attribute." I'm trying to use this feature to dynamically set the selected attributes on <option> s. I'm finding that I can dynamically set the disabled attribute, but the selected attribute is always omitted, no whether the boolean is true or false. Given this handlebars template: <option disabled={{false}} selected={{false}}>One</option> <option disabled={{true}} selected={{true}}>Two</option> I get the following HTML: <option>One</option> <option disabled

Ember.js: replacing simple linkTo helper with a view

为君一笑 提交于 2019-12-04 16:50:11
I've got an app with basic functionality built out. I'm not going through and adding additional features. In this case I need to convert a simple button, currently using linkTo , to a View. Problem is that I'm not sure how to convert one to the other and still keep the link intact. How do I do this conversion? Here's the code I have now: <script type="text/x-handlebars" data-template-name="accountItem"> {{#each account in controller}} {{#linkTo "account" account}} <img {{bindAttr src="account.icon"}} /> {{/linkTo}} {{/each}} </script> and here's the code I'm going to have: <script type="text/x

How to pass Express response object to frontend JS object

倾然丶 夕夏残阳落幕 提交于 2019-12-04 16:49:29
My controller is sending lat/lng data to my Handlebars view via res.render. res.render('coords', viewModel); 'viewModel' contains an array of objects, with each object containing a name of a location, lat, and lng. I want to take this information and plot markers on a Google map in my view. When I attempt to inject the data by way of Handlebars into an inline JS variable... <script> var viewMarkers = {{viewModel}}; console.log(viewMarkers); </script> I get this in my console... <script> var viewMarkers = [object Object],[object Object]; console.log(viewMarkers); </script> I'm only a beginner

Accordion wizard with multiple steps in ember

依然范特西╮ 提交于 2019-12-04 15:49:30
I am using ember to built a "wizard accordion" . Basically what I want is: an accordion which is always shown the accordion contains all the steps one step is active but it is also possibly to change the header of previous steps each step has its own model (e.g. Selecting from countries in first step, selecting from products in second) it should be possible to jump back and force between steps out of all the selections a central model is built which is sent to the server after the final step The number of steps is dynamic and sometimes certain steps are skipped The architecture i thought about