handlebars.js

handlebars array of json object

只谈情不闲聊 提交于 2019-12-17 17:31:37
问题 i need to template with handlebars an array of json object:(by chrome console) [object,object,object,object] where every object is composed by this property:name,surname,ecc. I've understood that is impossible to put array of object in handlebars but we must create an unique object with all property of all object of array. Can anyone suggest me a function to create it 回答1: You could set your array as a property of a wrapper object when calling the template. For example, with objects as the

How do I access an access array item by index in handlebars?

流过昼夜 提交于 2019-12-17 02:53:01
问题 I am trying to specify the index of an item in an array within a handlebars template: { people: [ {"name":"Yehuda Katz"}, {"name":"Luke"}, {"name":"Naomi"} ] } using this: <ul id="luke_should_be_here"> {{people[1].name}} </ul> If the above is not possible, how would I write a helper that could access a spefic item within the array? 回答1: Try this: <ul id="luke_should_be_here"> {{people.1.name}} </ul> 回答2: The following, with an additional dot before the index , works just as expected. Here,

Logical operator in a handlebars.js {{#if}} conditional

蹲街弑〆低调 提交于 2019-12-16 19:52:37
问题 Is there a way in handlebars JS to incorporate logical operators into the standard handlebars.js conditional operator? Something like this: {{#if section1 || section2}} .. content {{/if}} I know I could write my own helper, but first I'd like to make sure I'm not reinventing the wheel. 回答1: This is possible by 'cheating' with a block helper. This probably goes against the Ideology of the people who developed Handlebars. Handlebars.registerHelper('ifCond', function(v1, v2, options) { if(v1 ===

Insert partial/component at dynamic location

痴心易碎 提交于 2019-12-14 04:25:08
问题 I created a blog where I've got a {{downloads}} component showing the downloads which belong to a post. Currently I render the downloads below {{{post.content}}} . I'd like to have a special string withing post.content like [postDownloads] and render {{downloads}} there. Is this somehow possible or are there other approaches to solve this problem? I put together an easy example illustrating one of the use-cases I'm trying to solve: http://emberjs.jsbin.com/raresalihu/3/edit App = Ember

ember.js model data is not being output by the collectionView

╄→гoц情女王★ 提交于 2019-12-14 04:21:39
问题 I am at sea, and would be grateful for any help, with the latest version of Ember. Using the todo example, i've tried to include routes and DS models in the following adapted http://jsfiddle.net/5HMzu/3/ When I use a #each controller in the handlebar template, output is as expected; replacing that with a CollectionView and trying to tie that to the data source, nothing is being output. The inserted code: App.PersonCollectionView = Ember.CollectionView.extend({ itemViewClass: "App

Using AJAX in Node js and displaying data using Handlebars

风格不统一 提交于 2019-12-14 03:11:45
问题 I am using AJAX and Handlebars to get data from my MongoDB without refreshing the page and represent it in an easier manner. I have created a div with a search button where a user places his/her inputs. These inputs need to passed to my routes and then the results from my DB should be sent back from my routes, to the handlebar which will help me display the products. index.hbs <div id="search-form"> .... <input id="bhkInput" name="bmin" type="number"> <input id="priceMin" name="pf" type=

Handlebar if condition not working

百般思念 提交于 2019-12-14 03:05:35
问题 Unable to use if condition in Handlbars template. Below is my jquery Handlebars function below, $.each(data.response, function (i, item) { var source = $("#my-orders").html(); var template = Handlebars.compile(source); html += template(item); //alert(html); }); if(html){ $("#myorderss").html(html); } When I'm using if condition, its not working. {{#if id=='1'}} {{/if}} How to use if condition in handlebars template? 回答1: This is a misunderstanding of the if condition. Look at the #if

Cannot save model when using ember render helper

你说的曾经没有我的故事 提交于 2019-12-14 01:54:53
问题 I'm rendering a model into a parent template like this: {{render "teacher" teacher}} Here's it's controller: App.TeacherController = Ember.ObjectController.extend(App.EditableModelMixin, { actions: { saveTypes: function() { if (this.get('model')) console.log('Exists'); console.log(this.get('model')); console.log(this.get('model').get('isFulfilled')); this.get('model').save(); } } }); Here's the output when this method is called: Exists Class {isFulfilled: true, toString: function, constructor

Using Handlerbars with Yahoo Pipes

荒凉一梦 提交于 2019-12-13 19:15:30
问题 I'm trying to pull JSON feeds from a yahoo pipes source into my jQuery Mobile project using Handlebars.js with jQuery's ajax method. This method works without Handlebars, but there are some limitations. It doesn't show up in jquerymobile listview format, instead it pops out like a normal bullet list. Here's the source: var pipeURL = "http://pipes.yahoo.com/pipes/pipe.run?_id=mu3NkfY_3BGtncSIJhOy0Q&_render=json"; $.ajax({ url : pipeURL, dataType : "json", success : function(data) { console.log

including existing dom-element with handlebars

给你一囗甜甜゛ 提交于 2019-12-13 17:42:29
问题 Is there a way to include an existing dom-element through Handlebars, while being able to keep a reference to said dom-element? to explain: I have a jquery-element $el of which I want to include the dom-element ( $el[0] ) in a handlebars template. I have some jquery code that uses $el.html("new stuff") after handlebars has included the template (again: this template contains $el[0] The usual solution would be to rewrite the code by providing a selector so jquery can access the element.