温泉-导航器和滑动菜单-预推功能不起作用 [英] Onsen - navigator and sliding menu - function on prepush doesn't working

查看:85
本文介绍了温泉-导航器和滑动菜单-预推功能不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大问题. 我想使用导航器和滑动菜单.然后我需要在推后动作.

I have a big problem. I want to use navigator and sliding menu. Then I need to have some behaviour on postpush.

这是我的Codepen示例:

This is my codepen example:

http://codepen.io/anon/pen/zxgpVo

如果您留在Home并从这一点导航,那么您会看到console.log. 但是,如果您从滑动菜单更改并转到产品",则console.log无法正常工作,如果您返回首页",此处也将无法正常工作.

If you stay in Home and navigate from this point, then you see the console.log . But if you change from the sliding menu and go to Products, then the console.log doesn't working and if you return in Home doesn't working here anymore.

我用相同的名称创建2个导航器.这是对的事吗?也许这可能是问题所在?

I create 2 navigator with the same name. This is a right thing? Maybe this can be the problem?

<ons-template id="home.html">
  <ons-navigator page="page0.html" var="myNav"></ons-navigator>
</ons-template>

<ons-template id="products.html">
  <ons-navigator page="page_products.html" var="myNav"></ons-navigator>
</ons-template>

我不知道如何创建一个有效的示例.

I cannot figure out how can I create a working example.

我希望有人能帮助我.

谢谢!

推荐答案

我将尝试解释那里发生了什么(或者至少是我所了解的):

I will try to explain what is happening there (or, at least, what I understand):

项目的根是ons-sliding-menu,然后您有两个孩子,每个菜单项一个( home products ).每个孩子都是具有相同名称的ons-navigator,但这无关紧要,因为他们不会同时处于活跃状态". 当您进入 home 并使用menu.setMainPage('products.html')时,您将杀死 home 的导航器并创建 product 的导航器.您的事件仅在一开始就起作用,因为您仅将它们与ons.ready() 上的首页导航器相关联.因此,当您使用setMainPage时,您将破坏具有这些事件的导航器,而新的导航器将不会具有这些事件.

The root of your project is an ons-sliding-menu and then you have two childs, one per menu entry (home and products). Each child is an ons-navigator with the same name, but it should not matter since they will not be "alive" at the same time. When you are in home and use menu.setMainPage('products.html') you are killing home's navigator and creating product's navigator. Your events only work in the very beginning because you associate them to home's navigator on ons.ready() only the first time. Therefore, when you use setMainPage you are destroying the navigator that has those events, and the new navigators won't have them.

您可以在创建导航器本身时指定postpush/prepush事件,而不是将事件与ons.ready上的导航器相关联.有一些属性可以在文档中进行说明: http://onsen.io/reference/ons-navigator.html#attributes

Instead of associating the events to the navigator on ons.ready, you can specify the postpush/prepush events in the creation of the navigator itself. There are attributes to do that explained in the docs: http://onsen.io/reference/ons-navigator.html#attributes

希望有帮助!

这篇关于温泉-导航器和滑动菜单-预推功能不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆