在骨干木偶有没有办法判断一个观点是在一个区域已经显示出? [英] In backbone marionette is there a way to tell if a view is already shown in a region?

查看:106
本文介绍了在骨干木偶有没有办法判断一个观点是在一个区域已经显示出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于这样的事情:

View = Backbone.Marionette.ItemView.extend({ });

myView = new View();

//region already exists
myLayout.region.show(myView)

//some time later this gets called again:
myLayout.region.show(myView)

我可以看到currentView的文档,但这个似乎只在初始化应用。一旦被裁判员认为我可以查询该地区看到看法?无论是查看实例或类型将是有益的。展望Chrome的调试器,我不能看到,这将有助于该地区的任何属性/方法。

I can see currentView in the docs but this only seems to apply at initialisation. Once a view is shown can I query the region to see the view? Either the view instance or type would be helpful. Looking in Chrome's debugger I can't see any properties/methods on the region that would help.

对于希望这样做的动机是让我不要在一个区域再次显示一个静态项目视图,如果它已经显示,因为这可能(尤其是如果图像参与)导致屏幕上有轻微的闪烁效果。

The motive for wanting to do this is so I don't show a static item view in a region again if it is already displayed as this can (especially if images are involved) cause a slight flickering effect on the screen.

感谢

- 贾斯汀威利

推荐答案

您可以调用之前Show方法添加一个条件:

you can add a condition before calling show method:

if (myLayout.region.currentView != myView)
    myLayout.region.show(myView)

所以,如果你试图调用显示用相同的查看它不会显示出来。

so if you'll try to call show with the same View it wont be shown.

如果你想调用 region.show(MyView的)一旦你可以用这种方式查询:

if you want to call region.show(myView) once you can check in this way:

if (_.isUndefined(myLayout.region.currentView))
    myLayout.region.show(myView)

这篇关于在骨干木偶有没有办法判断一个观点是在一个区域已经显示出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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