【问题标题】:Meteor- Use a Blaze template in a React template from a routeMeteor - 在路由的 React 模板中使用 Blaze 模板
【发布时间】:2016-11-19 03:01:57
【问题描述】:

我目前正在通过使用 templates:tabs 包的流星开发一个反应式 Web 应用程序,该包旨在创建一个表格界面。我计划在这些选项卡中显示一个数据表,并根据选择的选项卡向不同的数据库发送查询,类似于cars.com

该应用程序已经有一个 FlowRouter 链接到两条不同的路线,我只希望其中一个出现选项卡。我希望显示选项卡的路由器如下。

#router.jsx
FlowRouter.route('/', {
action() {
    mount(MainLayout, {
      content: (<Landing />)
    }
  )
}
});

我需要创建以下模板: 模板名称="myTabbedInterface">

#Tabs.html
{{#basicTabs tabs=tabs}}
<div>


  <p>Here's some content for the <strong>first</strong> tab.</p>

</div>

<div>

  <p>Here's some content for the <strong>second</strong> tab.</p>

</div>

<div>

  <p>Here's some content for the <strong>third</strong> tab.</p>

</div>

  {{/basicTabs}}

</template>

这是包含模板助手的 JS 文件。

 #myTabbedInterface.js
 ReactiveTabs.createInterface({
  template: 'basicTabs',
  onChange: function (slug, template) {
    // This callback runs every time a tab changes.
    // The `template` instance is unique per {{#basicTabs}} block.
    console.log('[tabs] Tab has changed! Current tab:', slug);
    console.log('[tabs] Template instance calling onChange:', template);
  }
});

Template.myTabbedInterface.helpers({
  tabs: function () {
    // Every tab object MUST have a name and a slug!
    return [
      { name: 'First', slug: 'reports' },
      { name: 'Second', slug: 'sources' },
      { name: 'Third', slug: 'feedback' }
    ];
  },
  activeTab: function () {
    // Use this optional helper to reactively set the active tab.
    // All you have to do is return the slug of the tab.

    // You can set this using an Iron Router param if you want--
    // or a Session variable, or any reactive value from anywhere.

   // If you don't provide an active tab, the first one is selected by default.
    // See the `advanced use` section below to learn about dynamic tabs.
    return Session.get('activeTab'); // Returns "first", "second", or "third".
  }
 });

最后,这是“Landing”从我希望调用模板的路由器路由到的文件:

#Landing.jsx
`import {Blaze} from 'meteor/blaze';
import React, {Component} from 'react';
import { Meteor } from 'meteor/meteor';

export default class Landing extends Component{


 render(){
  return(


  <div>
   //Want to render template here
  </div>

     )
  }

}`

那么如何在 React 渲染中渲染 HTML 中的 (Blaze) 模板呢?谢谢。

【问题讨论】:

    标签: javascript templates meteor meteor-blaze meteor-react


    【解决方案1】:

    我建议不要使用 Blaze 包来解决 React 问题。我知道这不是你问的,但也许它有帮助。

    实现选项卡式 UI 确实是一项简单的任务,混合使用 React 和 Blaze 并不值得。一个很好的解决这个问题的库是React-Bootstrap,它实现了几个有用的 React 组件,比如&lt;Tab&gt;

    <Tabs>
      <Tab title="Apples">Apple content</Tab>
      <Tab title="Pears">Pear content</Tab>
      <Tab title="Melons">Melon content</Tab>
    </Tabs>
    

    但如果你想走那条路,你可以试试blazetoreact

    【讨论】:

    • 感谢您的建议!我对流星比较陌生,不确定是否有一种简单的方法可以集成我一直缺少的这些功能。
    猜你喜欢
    • 1970-01-01
    • 2016-03-24
    • 2014-11-04
    • 1970-01-01
    • 1970-01-01
    • 2016-05-10
    • 1970-01-01
    • 2014-05-09
    • 1970-01-01
    相关资源
    最近更新 更多