Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Meteor 如何访问HTML文件中的订阅?_Meteor_Publish Subscribe - Fatal编程技术网

Meteor 如何访问HTML文件中的订阅?

Meteor 如何访问HTML文件中的订阅?,meteor,publish-subscribe,Meteor,Publish Subscribe,通常,当我使用助手时,我可以访问返回的值,如下所示: Template.oveview.helpers({ item: function () { return Requests.find({}); }, 然后在客户端,我可以使用{{{{each item}},但我不知道在使用publish和subscribe时如何在.html中显示它们 这是我的出版物: Meteor.startup(() => { Meteor.publish('request

通常,当我使用助手时,我可以访问返回的值,如下所示:

Template.oveview.helpers({
    item: function () {
        return Requests.find({});
    },
然后在客户端,我可以使用
{{{{each item}}
,但我不知道在使用
publish
subscribe
时如何在
.html
中显示它们

这是我的出版物:

Meteor.startup(() => {
    Meteor.publish('requests', function queryRequests() {
        return Requests.find({});
    });

});
这是我的订阅:

Template.overview.onCreated(function() {
    Meteor.subscibe('requests');
});

如何在客户端显示发布返回的值?

您可以通过几种不同的方式使用它。您可以使用Meteor模板为现有HTML之间的每个项目插入HTML片段:

{{#each item}}
    {{> htmlTemplateName}}
{{/each}}
或者您可以将原始HTML放入
{{{each}
循环中:

{{#each item}}
    <p>{{propertyX}}</p>
    <p>{{propertyY}}</p>
{{/each}}

onCreated
回调中使用的
publish
subscribe
只会影响返回函数
请求的内容。find({})您没有任何要更改的内容。附言:你在代码中拼错了
subscribe
。我编辑了这个问题,以便更清楚地说明我想要什么。很抱歉一开始澄清得不好。我想显示publish的返回值发布的返回值是集合。还是要返回指向集合的光标?我希望能够在客户端显示集合。如果我从客户机中的帮助器返回集合,我就可以这样做。但我认为使用发布和订阅会更安全。但我似乎无法在客户端显示它们。@BehrouzRiahi正如@Magicbjørn所示,您只需在
{{{each…}}}{{/each}
循环中显示文档字段即可。
Router.configure({
    layoutTemplate: '_layoutTemplate',
    name: 'myTemplateName',
    waitOn: function() {
        return [
            Meteor.subscribe('requests'),
            //Add other subscriptions here
        ];
    }
});