spacebars

Meteor data context, passing array into each Spacebars loop

你离开我真会死。 提交于 2020-01-06 14:44:44
问题 In this Example 2 -- " Passing a data context " JS Template.overview.helpers({ users: [ { name: 'David' }, { name: 'Shaune' } ] }); HTML <template name="overview"> {{> userList users}} </template> <template name="userList"> {{#each this}} {{name}}<br> {{/each}} </template> Result David Shaune My goal is to pass an array of template names into Template.overview where users is, like so: <template name="overview"> {{#each templateArray }} {{> userList this }} {{/each}} </template> Where

Meteor Reactive Table Helper Arguments

对着背影说爱祢 提交于 2020-01-06 09:03:26
问题 Using the latest version of Meteor with aslagle:reactive-table. In Iron Router, I can pass a data context to my template: router.js: Router.route('/dates', { name: 'dates', data: { header_title: 'Dates & Times' } }); dates.html: <div class="bt-h1">{{header_title}}</div> Can I do something similar with ReactiveTables, i.e. pass "variable" from router.js? {{> reactiveTable collection=tests settings=variable}} 来源: https://stackoverflow.com/questions/28732955/meteor-reactive-table-helper

How do I iterate over an array of Strings with the Meteor Spacebars {{#each}} block?

喜你入骨 提交于 2020-01-05 08:25:19
问题 I have a Mongo.Collection that holds 'Question' objects. Each 'Question' has a property called choices Questions.insert({ text: 'What is the capitol of the US?', choices: [ "Washington D.C.", "Houston", "New York City", "Los Angeles" ], correctChoice: 0, date: new Date().toDateString() }); In my template I have this: <div class="question"> <div class="question-content"> <p>{{text}}</p> <ul> {{#each choices}} //????????? {{/each}} </ul> </div> </div> What should I put instead of the question

meteor, mongodb, spacebars, how do I display only 2 decimal places

感情迁移 提交于 2020-01-04 08:09:51
问题 I have a collection that has values like { "pctFail" : "0.3515500159795462" } and when I pass this to a template and display as {{myTemplate}}% it displays in my html as 0.3515500159795462%. How do I display this as 0.35% ? 回答1: You could override the data context's property with a template helper method: Template.myTemplate.helpers({ pctFail: function () { return this.pctFail.toFixed(2); } }) And then use {{pctFail}}% as before. If you insist on storing the numerical property as a string,

How do I indicate 'checked' or 'selected' state for input controls in Meteor (with spacebars templates)?

半腔热情 提交于 2020-01-03 18:48:28
问题 So I'm trying to be efficient and clean in my Spacebars templates as I work with Meteor. But I'm stumped by the way in which checkboxes and select options are to be dealt with. Suppose I want to have a checkbox set as checked or not depending on a flag that is in a document in one of my collections. I don't appear to be able to do the following: <input type='checkbox' id='item-{{this.item_id}}' {{#if checked}}checked{{/if}} /> When I try this, I get the following error: A template tag of type

How do I indicate 'checked' or 'selected' state for input controls in Meteor (with spacebars templates)?

淺唱寂寞╮ 提交于 2020-01-03 18:46:11
问题 So I'm trying to be efficient and clean in my Spacebars templates as I work with Meteor. But I'm stumped by the way in which checkboxes and select options are to be dealt with. Suppose I want to have a checkbox set as checked or not depending on a flag that is in a document in one of my collections. I don't appear to be able to do the following: <input type='checkbox' id='item-{{this.item_id}}' {{#if checked}}checked{{/if}} /> When I try this, I get the following error: A template tag of type

Spacebar/Meteor : Nested {{#if}} and Global template helpers

爷,独闯天下 提交于 2019-12-25 03:52:15
问题 I am willing to set the header of my app, based on Session variables. Here is the Spacebars template : {{#if session 'header'}} <header id="page_header"> {{#if session 'header_left'}} <a class="left_btn" href="{{session 'header_left'}}">{{session 'header_left'}}<a> {{/if}} <h1>{{session 'header'}}</h1> {{#if session 'header_right'}} <a class="right_btn" href="{{session 'header_right'}}">{{session 'header_right'}}<a> {{/if}} </header> {{/if}} Here is how I defined the global "session" helper :

Spacebar/Meteor : Nested {{#if}} and Global template helpers

别来无恙 提交于 2019-12-25 03:51:12
问题 I am willing to set the header of my app, based on Session variables. Here is the Spacebars template : {{#if session 'header'}} <header id="page_header"> {{#if session 'header_left'}} <a class="left_btn" href="{{session 'header_left'}}">{{session 'header_left'}}<a> {{/if}} <h1>{{session 'header'}}</h1> {{#if session 'header_right'}} <a class="right_btn" href="{{session 'header_right'}}">{{session 'header_right'}}<a> {{/if}} </header> {{/if}} Here is how I defined the global "session" helper :

In Spacebars, how to enter data between iterations {{# each}}?

主宰稳场 提交于 2019-12-23 22:04:08
问题 I'm using Spacebars and Meteor 1.2. In {{#each post}} , how to enter data after a specific iteration. For example after the second iteration. Example: 1º iteration | 2º iteration | data | 3º iteration | 4º iteration ... 回答1: Firstly, convert your cursor to an array and add an index attribute. You're also going to need a helper to check equality (or to tell you when the conditions are right to display something different): Template.myTemplate.helpers({ post: function(){ var cursor = Posts.find

How to get the @index of nested #each in meteor

时光毁灭记忆、已成空白 提交于 2019-12-23 08:36:22
问题 I have a 10x10 array representing 10 rows with 10 cells each. I want to draw a grid and set each cell's background-color according to the value in the array: a 0 value will be white and a 1 value will be black I've set up this CSS: .cell{ height: 20px; width: 20px; float: left; margin: 0; padding: 0; } .cell.live{ background-color: black; } .cell.dead { background-color: white; } I created a helper that will return 'live' or 'dead' according to the value in the array according to 2 arguments: