Meteor Blaze
这种方法被用于绘制模板到DOM。首先,我们将创建 myNewTemplate 之后渲染。 我们增加 myContainer 这将用来作为父元素的容器,所以render方法知道在何处呈现我们的模板。
meteorApp/client/app.html
<head>
<title>meteorApp</title>
</head> <body>
<div id = "myContainer">
</div>
</body> <template name = "myNewTemplate">
<p>Text from my new template...</p>
</template>
下一步,我们将创建渲染功能这将需要两个参数。第一个是将要渲染的模板,第二个是,我们上面提到的父元素。
meteorApp/client/app.js
Meteor.startup(function () {
if(Meteor.isClient) {
var myNewTemplate = Template.myNewTemplate;
var myContainer = document.getElementById('myContainer');
Blaze.render(myNewTemplate, myContainer);
}
});


如果需要被动地传递一些数据,你可以使用 renderWithData 方法。 HTML和前面的例子完全相同。
meteorApp/client/app.html
<head>
<title>meteorApp</title>
</head> <body>
<div id = "myContainer">
</div>
</body> <template name = "myNewTemplate">
<p>Text from my new template...</p>
</template>
我们可以在Meteor.renderWithData方法的第二个参数添加数据。其它两个参数和之前的实例相同,在这个例子中我们的数据将用于记录一些文本的功能。
meteorApp/client/app.js
Meteor.startup(function () {
if(Meteor.isClient) {
var myNewTemplate = Template.myNewTemplate;
var myData = function() {
console.log('Log from the data object...')
}
var myContainer = document.getElementById('myContainer');
Blaze.renderWithData(myNewTemplate, myData, myContainer);
}
});


我们可以添加 remove
meteorApp/client/app.html
<head>
<title>meteorApp</title>
</head> <body>
<div id = "myContainer">
</div>
</body> <template name = "myNewTemplate">
<p>Text from my new template...</p>
</template>
在这个例子中,我们将在三秒钟后移除模板。请注意,我们使用 Blaze.Remove方法 除去模板。
meteorApp/client/app.js
Meteor.startup(function () {
if(Meteor.isClient) {
var myNewTemplate = Template.myNewTemplate;
var myContainer = document.getElementById('myContainer');
var myRenderedTemplate = Blaze.render(myNewTemplate, myContainer);
Meteor.setTimeout(function() {
Blaze.remove(myRenderedTemplate);}, 3000);
}
});
| S.No. |
方法与细则
|
|---|---|
| 1 |
Blaze.getData([elementOrView]) 用于从渲染元素检索数据。
|
| 2 |
Blaze.toHTML(templateOrView) 用于渲染模板或视图字符串。
|
| 3 |
Blaze.toHTMLWithData(templateOrView, data) 用于渲染模板或视图字符串附加数据。
|
| 4 |
new Blaze.View([name], renderFunction) 用于创建新 Blaze 反应性的DOM部分。 |
| 5 |
Blaze.currentView 用于获取当前视图。
|
| 6 |
Blaze.getView([element]) 用于获取当前视图。
|
| 7 |
Blaze.With(data, contentFunc) 用于构造呈现一些内容与上下文的视图。
|
| 8 |
Blaze.If(conditionFunc, contentFunc, [elseFunc]) 用于构造呈现一些有条件的内容的视图。
|
| 9 |
Blaze.Unless(conditionFunc, contentFunc, [elseFunc]) 用于构造呈现一些有条件的内容(反转Blaze.if)的视图。
|
| 10 |
Blaze.Each(argFunc, contentFunc, [elseFunc]) 用于构建为每个项目呈现 contentFunct 的视图。 |
| 11 |
new Blaze.Template([viewName], renderFunction) 使用名称和内容构建新的Blaze视图。
|
| 12 |
Blaze.isTemplate(value) 如果值是一个模板对象则返回true。
|
Meteor Blaze的更多相关文章
- Using View and Data API with Meteor
By Daniel Du I have been studying Meteor these days, and find that Meteor is really a mind-blowing f ...
- 示例开发过程记录:meteor,react,apollo
本示例记录一个开发过程: 1)参考 Meteor React TUTORIAL教程 https://www.meteor.com/tutorials/react/creating-an-app 2). ...
- 网站开发只需数小时?Meteor 说这才是未来
原文: http://www.geekpark.net/topics/211573/ 那个想要挑战过去数十年沿用至今的网站开发模式的新势力来了. Meteor 是从 YC 孵化而出的现代网站开发平台, ...
- 【译】Meteor 新手教程:在排行榜上添加新特性
原文:http://danneu.com/posts/6-meteor-tutorial-for-fellow-noobs-adding-features-to-the-leaderboard-dem ...
- POJ 3669 Meteor Shower【BFS】
POJ 3669 去看流星雨,不料流星掉下来会砸毁上下左右中五个点.每个流星掉下的位置和时间都不同,求能否活命,如果能活命,最短的逃跑时间是多少? 思路:对流星雨排序,然后将地图的每个点的值设为该点最 ...
- 如何在Meteor中使用npm模块?
首先,请在AtmosphereJs上搜索有无相关的封装包.尽量采用已有的封装包,而不是自己封装. 有两种方法在项目中使用来自npm的模块. 封装为Meteor包并在项目中添加包.使用meteor cr ...
- windows下Meteor+AngularJS开发的坑
有复杂的地方我再开贴记录,这里只记录容易解决的坑. 1. windows下手工增加smart package.直接将下载下来的包扔到meteor package中.记得将文件夹名字改得和smart.j ...
- Meteor + node-imap(nodejs) + mailparser(nodejs) 实现完整收发邮件
版本信息: Meteor:windows MIS安装 0.6.4 node-imap:npm指定的0.8.0版,不是默认的0.7.x版. mailparser:npm安装0.3.6 以下是记录踩到的 ...
- 手工给Meteor增加smart package的方法
windows下无法装mrt(Meteor的包管理工具).不过还好smart package本身也就只是一个文件夹而已,不需要在Meteor中注册什么东西.所以直接把smart package扔到me ...
随机推荐
- 世平信息(W 笔试)
选择题 大题 1.启动Thread的方法有几种 算法题 1.写出冒泡排序算法
- Js 之获取QueryString的几种方法
一.正则匹配 function getQueryString(name) { var reg = new RegExp('(^|&)' + name + '=([^&]*)(& ...
- IIR数字滤波器
对于N阶IIR的计算方程式为: 一阶 Y(n)=a∗X(n)+(1−a)∗Y(n−1) 二阶 y[n]=b0⋅x[n]+b1⋅x[n−1]+b2⋅x[n−2]−a1⋅y[n−1]−a2⋅y[n−2]
- 网页添加tittle前的图标logo
在head标签中 <link rel="icon" href="~/favicon.ico" type="image/x-icon" ...
- JavaScript设计模式基础之this、call、apply
1.this的指向 除去不常用的with和eval,具体应用中this指向大概能分为4种情况分别是 1.作为对象的方法调用. 2.作为普通函数的方法调用. 3.Function.prototype.c ...
- Puppeteer-常规操作一
这里不讲 Puppeteer 怎么使用,主要讲一些常规操作在这里如何通过另类方法实现.等实现后,你就会感觉,嗯~~ 真香! 场景一 已经找出要的元素,现在有需求再继续寻找他的子元素 第一种.将父元素带 ...
- 洛谷 P1085 不高兴的津津
这道题就是经典的条件分支的题https://www.luogu.org/problemnew/show/P1085 code: #include <stdio.h> int main() ...
- 【转载】form表单的两种提交方式,submit和button的用法
1.当输入用户名和密码为空的时候,需要判断.这时候就用到了校验用户名和密码,这个需要在jsp的前端页面写:有两种方法,一种是用submit提交.一种是用button提交.方法一: 在jsp的前端页面的 ...
- windows 上使用virtualenv进行python多版本转换
近期因为需要在python2.7和Python3.6上进行工作学习,可是笔记本只配置了python3.6环境. 所以打算使用virtualenv这个强大的工具进行多版本转换: 一.首先,默认已经配置好 ...
- activemq常用配置
所用版本为apache-activemq-5.15.4的版本 修改端口号 当端口号冲突时,可以修改这两个端口号.修改activemq.xml 修改里面的61616端口.修改jetty.xml,修改里面 ...