我目前正在通过使用 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) 模板呢?谢谢你。