简体   繁体   English

无法使mizzao / meteor-autocomplete与集合一起使用

[英]Unable to get mizzao/meteor-autocomplete to work with collection

I am using mizzao/meteor-autocomplete and am having problems in trying to get it to work. 我正在使用mizzao / meteor-autocomplete ,在尝试使其正常工作时遇到问题。

When viewing the page in my browser, I am getting no results at all when typing any text. 在浏览器中查看页面时,键入任何文本都没有任何结果。 I've created the appropriate collection: 我已经创建了适当的集合:

Institutions = new Mongo.Collection("institutions");

and know that there is data in the actual db, however still no success. 并且知道实际数据库中有数据,但是仍然没有成功。

I've included my files below. 我在下面包括了我的文件。

publications.js (located in the server folder) publications.js (位于服务器文件夹中)

Meteor.publish('institutions', function(args) {
    return Institutions.find({}, args);
});

registrationStart.js registrationStart.js

I've two helpers; 我有两个帮手; one that actually powers the search and the other that should be returning the institutions. 一个实际上为搜索提供动力,另一个应该返回机构。 I have also tried this with the token: '@' argument with no success. 我也尝试使用token: '@'参数,但没有成功。

if (Meteor.isClient) {

    Template.registrationStart.helpers({
    settings: function() {
        return {
            position: "top",
            limit: 7,
            rules: [{
                collection: Institutions,
                field: "name",
                options: '',
                matchAll: true,
                template: Template.institutionSelectDisplay
            }]
        };
    },

    institutions: function() {
        return Instititions.find();
    }
    });

    Template.registrationStart.events({
    "autocompleteselect input": function(event, template, doc) {
        // Session.set(event.target.name, event.target.value);
        console.log("selected: ", doc);
        console.log("event.target.name: ", event.target.name);
        console.log("event.target.value: ", event.target.value);
    }
    });

}

registrationStart.html template registrationStart.html模板

<template name="registrationStart">
    <div class="panel-body" id="loginForm">
    <h2 class="pageTitle">veClient Registration</h2>
    <form>
        <div>&nbsp;</div>
        <fieldset>
            {{> inputAutocomplete settings=settings id="institution" class="input-xlarge" placeholder="type institution here"}}
        </fieldset>
        <div>&nbsp;</div>
        <button type="submit" class="btn btn-primary btn-sm">Continue Registration</button>
    </form>
    </div>
</template>

And the template to be rendered 和要渲染的模板

<template name="institutionSelectDisplay">
    <p class="inst-state">{{city}}, {{state}}</p>
    <p class="inst-name">{{name}}</p>
    <p class="inst-description">{{email}}</p>
</template>

Problem resulted because there was no subscription to the "institutions" publication. 由于没有订阅“机构”出版物而导致出现问题。 So need to add a subscribe statement to the registrationStart.js file: 因此,需要在registrationStart.js文件中添加一个订阅语句:

Meteor.subscribe('institutions');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM