SAPUI5-每次显示视图时调用哪种方法? [英] SAPUI5-Which method to call once a view is displayed everytime?

查看:22
本文介绍了SAPUI5-每次显示视图时调用哪种方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在每次显示视图之前做一些逻辑.我不能使用渲染之前的方法,因为它只在第一次创建和显示视图时调用一次.请帮助.有任何想法吗?

I want to do some logic before a view is displayed every time.I cannot go with before rendering method since it is called only once when the view is created and shown for the first-time.Pls help.Any ideas?

推荐答案

为什么认为控件的渲染前方法只调用一次?你有任何示例代码吗?

Why do you think the before rendering method of a control is called only once? Do you have any sample code?

我在 jsbin (http://jsbin.com/qikokayo/1/edit?html,output) 供您查看.它清楚地表明 onInit 被调用一次,但 onBeforeRendering 每次都被调用......

I've created a quick a dirty example on jsbin (http://jsbin.com/qikokayo/1/edit?html,output) for you to have a look at. It clearly shows that onInit is called once but onBeforeRendering is called every time...

同样看到这个片断从OpenUI5 SDK 这解释了:

Also see this snippet from the OpenUI5 SDK which explains:

onInit() - 在实例化视图及其控件时调用(如果可用)已经创建.可以用来修改之前的View它显示为绑定事件处理程序并执行其他一次性操作初始化.

Lifecycle Hooks

onInit() - Called when a View is instantiated and its controls (if available) are already created. Can be used to modify the View before it is displayed to bind event handlers and do other one-time initialization.

onExit() - 当视图被销毁时调用.用这个来免费资源并完成活动.

onExit() - Called when the View is destroyed. Use this one to free resources and finalize activities.

onAfterRendering() - 在渲染视图时调用(因此它的 HTML 是文档的一部分).渲染后的操作HTML 可以在这里完成.这个钩子和 SAPUI5 控制的钩子是一样的渲染后获取.

onAfterRendering() - Called when the View has been rendered (therefore its HTML is part of the document). Post-rendering manipulations of the HTML can be done here. This hook is the same one that SAPUI5 controls get after being rendered.

onBeforeRendering() - 在控制器的视图之前调用重新渲染.在钩子应该是的情况下,您将使用 onInit()仅在第一次渲染之前调用.

onBeforeRendering() - Is invoked before the Controller's View is re-rendered. You would use onInit() in the case that the hook shall be invoked only before the first rendering.

对于没有视图的控制器,不会调用生命周期钩子.

For Controllers without a View, no lifecycle hooks will be called.

这篇关于SAPUI5-每次显示视图时调用哪种方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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