看看这个使用Blaze指南,看起来Blaze支持{{#if}}
和{{else}}
声明,但我还没有看到if-else语句的例子.Blaze是否支持此功能?或者我必须在else块中执行额外的if块,这可能会变得很难看.
我试过了{{else if}}
,但这给了一个错误.
{{#if en}}{{text.en}}{{else if tc}}{{text.tc}}{{/if}}
Run Code Online (Sandbox Code Playgroud) 我该如何渲染这个流星火焰模板?我想使用IF的否定,但我找不到任何地方如何使用它.
<ul>
{{#each pages}}
{{#if (--NOT--) isCover }}
<li> some content {{value}} </li>
{{/if}}
{{/each}}
</ul>
Run Code Online (Sandbox Code Playgroud)
之前的研究未找到解决方案 https://github.com/meteor/meteor/wiki/Using-Blaze 检查Spacebars中的相等性?
注意:如果我只使用该if
语句工作没有问题,我也可以做,else
但我想只有if(!isCover)
解决方案
如何从另一个模板助手中引用模板助手?例如...
Template.XXX.helpers({
reusableHelper: function() {
return this.field1 * 25 / 100; //or some other result
},
anotherHelper: function() {
if (this.reusableHelper() > 300) //this does not work
return this.reusableHelper() + ' is greater than 300';
else
return this.reusableHelper() + ' is smaller than 300';
}
});
Run Code Online (Sandbox Code Playgroud)
我也尝试过Template.instance().__ helpers.reusableHelper - 一切都没有运气.
或者有没有办法定义反应模板实例变量?
XXX是一个在同一页面上呈现多次的子模板.
我正在创建一个包,对于客户端,我需要添加一些静态文件,如字体和图像.在尝试了一些过时的解决方案后,我发现似乎没有什么对我有用.我该如何添加这些文件?在我的包中创建一个公用文件夹?添加文件api.addFiles
?这甚至可能吗?
有没有一种干净的方法来获取当前模板的父模板?Meteor的API中没有正式记录的内容.我在谈论的是Blaze.TemplateInstance
,而不是上下文(即没有Template.parentData
).
例如,我有一个数组:var arr = ['a','b']并且只想获得模板中的第一个元素
我正在使用Meteor的帐户-ui.有没有办法检查用户是否登录模板而不编写自定义帮助程序代码?
伪代码:
{{#if userIsLoggedIn }}
You're logged in
{{/if}}
Run Code Online (Sandbox Code Playgroud)
如果没有,那么最干净,最惯用的方式是什么?
我在这里只关心客户端.
谢谢.
如何使用each
输入值events
?希望我的下面代码能很好地解释你.
HTML:
<template name="UpdateAge">
{{#each Name}}
<div data-action="showPrompt">
<div>
Some content
</div>
<div>
<div>
Some content
</div>
</div>
<div>
Name : {{name}}
Age : <input type="text" name="age" value="{{age}}"/> //I need to access age values in event
</div>
</div>
{{/each}}
<template>
Run Code Online (Sandbox Code Playgroud)
JS:
Template.UpdateAge.events({
'click [data-action="showPrompt"]': function (event, template) {
console.log(event.target.age.value); // TypeError: event.target.age.value is undefined
}
});
Run Code Online (Sandbox Code Playgroud)
我不知道我的方法是否适合传递参数值,events
所以欢迎提出建议.
2技术:
我来自流星边,我个人喜欢使用{{mustache}}(把手)从数据驱动gui,反应式会话/数据库使这真的高效和直观.
现在来了famo.us及其所有优点,但基于代码的gui的缺点是不再有把手的地方......
如何为流星中的所有模板创建一个函数?
index.js
// Some function
function somefunction(){
return true;
}
Run Code Online (Sandbox Code Playgroud)
Test1.js
Template.Test1.events({
'click button' : function (event, template){
//call somefunction
}
});
Run Code Online (Sandbox Code Playgroud)
Test2.js
Template.Test2.events({
'click button' : function (event, template){
//call some function
}
});
Run Code Online (Sandbox Code Playgroud)