我目前正在通过 Meteor 开发一个响应式(Reactive) Web 应用程序,该应用程序利用 templates:tabs 包,该包旨在创建一个表格界面。我计划在这些选项卡中显示数据表,并根据选择的选项卡将查询发送到不同的数据库,类似于 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) 模板呢?谢谢。
最佳答案
我建议不要使用 Blaze 包来解决 React 问题。我知道这不是您所要求的,但也许它会有所帮助。
实现选项卡式 UI 确实是一项简单的任务,混合使用 React 和 Blaze 并不值得。解决这个问题的一个不错的库是 React-Bootstrap ,它实现了几个有用的 React 组件,例如 <Tab>
:
<Tabs>
<Tab title="Apples">Apple content</Tab>
<Tab title="Pears">Pear content</Tab>
<Tab title="Melons">Melon content</Tab>
</Tabs>
但如果你想走那条路,你可以尝试 blazetoreact .
关于javascript - Meteor - 在路由中的 React 模板中使用 Blaze 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38403943/