在Ubuntu上运行
Data.js
//Collections
Database = new Meteor.Collection('data');
if (Meteor.isClient) {
Template.main.data = function () {
var c = Database.find();
return c;
};
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
});
}
Run Code Online (Sandbox Code Playgroud)
data.html
<head>
<title>data</title>
</head>
<body>
{{> main}}
</body>
<template name="main">
{{data}}
</template>
Run Code Online (Sandbox Code Playgroud)
我使用mongo插入数据库:
> db.Database.insert({title: 'ShouldWork'});
> db.Database.find();
{ "_id" : ObjectId("5296403855ee6e1350b35afb"), "title" : "ShouldWork" }
Run Code Online (Sandbox Code Playgroud)
然而,当我运行网站时,它只返回[object Object] ..
应该有自动发布和不安全,这已经成为我学习框架的障碍.
Template.display_time.time = function() {
var date = new Date();
var hour = date.getHours();
var minute = date.getMinutes();
var now = addZero(hour) + ":" + addZero(minute);
return now
};
Run Code Online (Sandbox Code Playgroud)
目前我正在使用此代码来显示时间.但我一直在尝试使用简单的javascript来每秒更新它,但它不会出现在页面上.使用上述功能是否有流星友好的方式来做到这一点?就像在1秒间隔使用setTimeout一样..
我以前使用的javascript.
function updateTime() {
var currentTime = new Date();
var hours = currentTime.getHours();
var minutes = currentTime.getMinutes();
if (hours < 10)
{
hours = "0" + hours;
}
if (minutes < 10)
{
minutes = "0" + minutes;
}
var v = hours + ":" + minutes + " ";
setTimeout("updateTime()",1000); …Run Code Online (Sandbox Code Playgroud) JS
Colors = new Meteor.Collection("colors");
Template.col_list.cols = function () {
return Colors.find();
};
Run Code Online (Sandbox Code Playgroud)
因此,此代码将输出从Col.find到html中的handlebar cols的所有内容
HTML
{{#each cols}}
{{name}}, {{RGB}}, {{HEX}}
{{/each}}
Run Code Online (Sandbox Code Playgroud)
但是说我想要一个输入框,这样我就可以搜索颜色的名称,所以它只显示该颜色的信息或任何以我在输入框中键入的颜色开始的颜色.
示例:输入="bl"输出应为黑色,蓝色或以bl开头的任何其他内容.
在实践中,我一直在寻找任何这方面的例子,但我还没有找到.
到目前为止,我已经达到了这个效果,但它没有产生任何好运.
Template.col_list.events({
'click .search': function() {
Colors.find(name: $('col_name').val());
}
});
Run Code Online (Sandbox Code Playgroud)