首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >添加选项卡后,Onsen用户界面导航无法工作

添加选项卡后,Onsen用户界面导航无法工作
EN

Stack Overflow用户
提问于 2015-03-08 17:50:58
回答 1查看 1.5K关注 0票数 1

我不能让导航和制表符一起工作。我有一个列表页面,搜索页面和详细信息页面。由于某些原因,我无法使列表页在导航时持久化。即使我使用的是app.navi.pushPage('detail.html'),也不会显示详细信息页。在添加选项卡之前,一切都很好。对我做错了什么有什么想法吗?

此外,我还需要从列表和搜索页面访问详细页面。

代码语言:javascript
运行
复制
<ons-navigator page="list.html" var="app.navi"></ons-navigator>

<ons-tabbar>
    <ons-tab page="favourites.html" label="Favourites" icon="fa-heart"></ons-tab>
    <ons-tab page="list.html" label="Near Me" icon="fa-map-marker" active="true"></ons-tab>      
    <ons-tab page="search.html" label="Search" icon="fa-search"></ons-tab>
</ons-tabbar>

<ons-template id="list.html">
    <ons-page id="list-page">
        <ons-toolbar>
            <div class="center">Near Me</div>
        </ons-toolbar>            
        <ons-list id="lst-estblshmnt"></ons-list>
    </ons-page>
</ons-template>

<ons-template id="search.html">
    <ons-page id="search-page">
        <ons-toolbar>
            <div class="center">Search</div>
        </ons-toolbar>
        <ons-row>
            <ons-col>
                <input id="srch" type="search" class="search-input">
            </ons-col>
            <ons-col width="75px" style="display: none">
                <ons-button id="btn-cancel-search" modifier="quiet">Cancel</ons-button>
            </ons-col>
        </ons-row>            
        <ons-list id="lst-srch"></ons-list>
    </ons-page>
</ons-template>

<ons-template id="detail.html">
    <ons-page id="detail-page">
        <ons-toolbar>
            <div class="left"><ons-back-button>Back</ons-back-button></div>
            <div class="right">
                <ons-toolbar-button id="btn-fllw"><ons-icon icon="fa-heart-o"></ons-icon></ons-toolbar-button>
            </div>
        </ons-toolbar>
        <ons-row>
            <ons-col id="establishment-details">
                <header>
                    <center class="item-title">Title</center>
                </header>
                <div class="item-details">
                    <ons-row>
                        <ons-col>
                            <p class="item-address"></p>
                            <p class="item-city"></p>
                            <p class="item-postal_code"></p>
                        </ons-col>                           
                    </ons-row>
                </div>
            </ons-col>
        </ons-row> 
    </ons-list>          

    </ons-page>
</ons-template>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-03-09 04:18:43

您不能将<ons-navigator><ons-tabbar>结合起来。如果使用tabbar元素,则可以使用setActiveTab(index, [options])切换页面。我使用您提供的模板创建了一个工作样例,并在更改活动页面的<ons-button>模板中添加了一个list.html。有关选项卡元素的更多信息,请查看这里。如果你需要更多的帮助,请告诉我:)

代码语言:javascript
运行
复制
<body>

    <ons-tabbar var="tabbar">
        <ons-tabbar-item
            icon="home"
            label="Home"
            page="list.html"
            active="true"></ons-tabbar-item>
        <ons-tabbar-item
            icon="comment"
            label="Comments"
            page="search.html"></ons-tabbar-item>
        <ons-tabbar-item
            icon="gear"
            label="Settings"
            page="detail.html"></ons-tabbar-item>
    </ons-tabbar>
    
    <ons-template id="list.html">
    <ons-page id="list-page">
        <ons-toolbar>
            <div class="center">Near Me</div>
        </ons-toolbar>            
        <ons-list id="lst-estblshmnt"></ons-list>
        <ons-button id="btn-switch-search"  ng-click="tabbar.setActiveTab(2)">Cancel</ons-button>
    </ons-page>
</ons-template>

<ons-template id="search.html">
    <ons-page id="search-page">
        <ons-toolbar>
            <div class="center">Search</div>
        </ons-toolbar>
        <ons-row>
            <ons-col>
                <input id="srch" type="search" class="search-input">
            </ons-col>
            <ons-col width="75px" style="display: none">
                <ons-button id="btn-cancel-search" modifier="quiet">Cancel</ons-button>
            </ons-col>
        </ons-row>            
        <ons-list id="lst-srch"></ons-list>
    </ons-page>
</ons-template>

<ons-template id="detail.html">
    <ons-page id="detail-page">
        <ons-toolbar>
            <div class="left"><ons-back-button>Back</ons-back-button></div>
            <div class="right">
                <ons-toolbar-button id="btn-fllw"><ons-icon icon="fa-heart-o"></ons-icon></ons-toolbar-button>
            </div>
        </ons-toolbar>
        <ons-row>
            <ons-col id="establishment-details">
                <header>
                    <center class="item-title">Title</center>
                </header>
                <div class="item-details">
                    <ons-row>
                        <ons-col>
                            <p class="item-address"></p>
                            <p class="item-city"></p>
                            <p class="item-postal_code"></p>
                        </ons-col>                           
                    </ons-row>
                </div>
            </ons-col>
        </ons-row> 
    </ons-list>          

    </ons-page>
</ons-template>

</body>

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28929810

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档