Rendering a template from the imports folder in Meteor

筅森魡賤 提交于 2019-12-24 18:51:41

问题


From what I understand, the purpose of the imports folder is to store all your code that you import into main.js in the client folder. I'm trying to implement easysearch:autosuggest and I got a basic example working with the following in my main.html on the client folder:

<body>

  <div id="render-target"></div>
    <div>
        {{>searchBox}}

    </div>
</body>

<template name="searchBox">

    <div class="autosuggest-component">
        {{> EasySearch.Autosuggest index=PlayersIndex}}
    </div>

</template>

In my main.js in the client folder I'm importing App from my '../imports/ui/App.js' and rendering it:

Meteor.startup(() => {

 render(<App />, document.getElementById('render-target'));

});

So I've tried pasting the template in main.html into the render() function inside App.js in the imports folder, however this gives me an unexpected token error pointing to {{>searchBox}}. I'm new to Meteor/node and I'm not really sure what I'm doing wrong, also trying to understand if I'm doing things correctly from a structural standpoint. If I have to build my app client side, what's the point of the imports folder? How can I get this to work using App.js and render()?


回答1:


The problem here is that you are mixing two front end libraries together.

A frontend library is a tool we can use to help us build the user interface of our applications. Some popular ones that people use with Meteor are Blaze, React and Angular.js

The syntax you are using {{>searchBox}} is syntax used by the Blaze library to render a Blaze template.

However, in your Meteor.startup() block you are using code needed by React. You've also indicated that you have been following the React tutorial. Unfortunately, you can't mix the two of these.

I suggest you start again and follow this tutorial instead. It's the exact same tutorial you've already been doing but it's the Blaze version - which will work with the syntax you've been using - {{>searchBox}}

I hope that helps



来源:https://stackoverflow.com/questions/49179641/rendering-a-template-from-the-imports-folder-in-meteor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!