SAPUI5: Difference between invalidate and rerender

Jon*_*ink 2 javascript rendering sapui5

After digging into the code a bit I see that invalidate() on a control will increase a counter which seems to mark the control as invalidated. This seems to lead to a rerender.

So if you have a control that you want rerendered, is it better practice to use invalidate() or rerender()?

How does a rerender actually get triggered? (other than by explicitly invoking it of course)

sir*_*ion 5

两者都标记为"受保护",这意味着除非您真正深入开发自定义控件,否则不应调用其中任何一个.

当(例如)属性发生更改时,控件将失效.在这种情况下,您通常需要重新呈现控件,这就是默认情况下setter调用invalidate的原因.

当您在自定义控件中覆盖invalidate方法时,您可以分析失效的来源,然后决定是否确实要重新渲染等.例如,参见unified.Shell,它根据来源决定对invalidate做什么: https ://sapui5.netweaver.ondemand.com/sdk/resources/sap/ui/unified/Shell-dbg.js line 1539ff

同样:受保护意味着它不应该从外部调用(并且除了调试之外它不应该是必需的).