从流星1.0
显示数据在启动时我从一个JSON文件数据添加到流星像这样:从流星1.0
13 if (Meteor.isServer) {
14
15 //startup
16 Meteor.startup(function() {
17 if(Plugins.find().count() === 0) {
18 var plugins_data = JSON.parse(Assets.getText('plugins_data.json'));
19 _.each(plugins_data, function(){
20 Plugins.insert(plugins_data);
21 console.log('created new plugin record');
22 });
23 }
24 });
25
26 }
我有一个叫plugins
集合,看起来像使用meteor mongo
db.plugins.find().pretty()
来查看数据:
"222" : {
"plugin-name-one" : {
"data" : [
{
"id" : 888,
"title" : ""
}
]
}
},
"223" : {
"plugin-name-two" : {
"data" : [
{
"id" : 555,
"title" : ""
}
]
}
},
这里怎么我试图来显示数据:
3 if (Meteor.isClient) {
4
5 Template.list.helpers({
6 list_all: function() {
7 return Plugins.find();
8 }
9 });
10
11 }
和HTML模板:
5 <body>
6 <h1>Welcome to Meteor!</h1>
7 {{> list}}
8 </body>
9
10
11 <template name='list'>
12 {{#each list_all}}
13 <h1>{{name}}</h1>
14 {{/each}}
15 </template>
如何显示从外地(和字段名)数据plugin-name-1
和plugin-name-2
从我的收藏蒙哥显示?我无法从文档中找到任何信息。我如何正确显示这些数据?
您没有任何称为name
的池。
此外,更好的方法来检查是否有收集创建使用if(Plugins.findOne())
。
更重要的是,ENUMERATE_THIS
是一个对象,所以以后改名{{name}}
将返回[Object object]
如果我没有记错
编辑: 确定后,编辑我想我知道你想做什么,IMO结构应该像这样
{
name:"plugin_one",
"data" : [
{
"id" : 888,
"title" : ""
}
]
},
{
name:"plugin_two",
"data" : [
{
"id" : 888,
"title" : ""
}
]
},
我假设你想保留更多的数据在一个插件,这就是为什么有一个数组,如果没有结构是这样的
{
name:"plugin_one",
id : "888",
title : ""
},
{
name:"plugin_two",
id : "888",
title : ""
},
和HTML,你可以做这样的事情:
<template name='list'>
{{#each list_all}}
<h1>{{name}} {{data.id}}</h1>
{{/each}}
</template>
或不带阵列
<template name='list'>
{{#each list_all}}
<h1>{{name}} {{id}}</h1>
{{/each}}
</template>
那么如何显示'enumerate_this'?你能告诉我一些示例代码吗?我只想显示'enumerate_this'的名字,以便它能呈现'
enumerate_this data 1
','enumerate_this data 2
'等等 – Kush 2014-11-02 20:34:23ENUMERATE_THIS是一个对象,而不是一个字符串。现在我不在Linux上,我想'{{ENUMERATE_THIS.data.id}}或'{{ENUMERATE_THIS.data [0] .id}}'会返回值 – Sindis 2014-11-02 20:37:46
哦,不,所以我想显示什么是在'enumerate_this'字段中,如果你知道我的意思(抱歉,如果我不清楚),不指定字段名。有什么建议么? – Kush 2014-11-02 20:39:21
由我使用的是默认的'自带流星通过启用autopublish'包的方式默认情况下,当我学习流星时不使用任何其他软件包 – Kush 2014-11-02 20:28:08