我正在使用 Riot JS,在我的 index.html 中,我有 3 个自定义标签——标题、登录面板和候选面板。在我的主 app.js 中,在 $(document).ready 的回调函数中,我执行当前路由并注册一个路由更改处理函数。在我的 switchView 中,我卸载了所有自定义标签,然后尝试仅安装与正在切换的当前视图相关的标签。这是我的代码。如果我卸载,则页面上不会显示任何内容
索引.html
<body>
<header label="Hire Zen" icon="img/user-8-32.png"></header>
<login-panel class="viewTag" id="loginView"></login-panel>
<candidates-panel id="candidatesView" class="viewTag"></candidates-panel>
<script src="js/bundle.js"></script>
</body>
应用程序.js
function switchView(view) {
if(!view || view === '') {
view = 'login'
}
//unmount all other panels and mount only the panel that is required
//TODO: unmount all view panels and mounting only required panel is not working
//riot.unmount('.viewTag')
riot.mount(view+'-panel')
$('.viewTag').hide()
$(view+'-panel').show()
}
$(document).ready(function () {
RiotControl.addStore(new AuthStore())
RiotControl.addStore(new CandidatesStore())
riot.mount('header')
//register route change handler
riot.route(function (collection, id, action) {
switchView(collection)
})
riot.route.exec(function (collection, id, action) {
switchView(collection)
})
})