我有一个 sapui5 表,我在表滚动条上调用了一个滚动函数。它仅在我使用 setTimeout
时有效。我假设这是因为表中的数据在实际表加载之后略有加载。
这是我的代码:
setTimeout(function () {
var lastScroll = 0;
$("#__xmlview0--players-vsb-sb").scroll(function () {
var st = $(this).scrollTop();
if (st > lastScroll) {
console.log("scrolling down");
} else {
console.log("scrolling up");
}
lastScroll = st;
});
}, 900);
我尝试使用 onAfterRendering
函数作为替代方法,但我无法让它工作。有谁知道 setTimeout
的替代方法?
这是我的 JSBin .
最佳答案
如果这是一个 sap.m.Table,您可以使用 sap.m.ListBase 中的 updateFinished 事件,请参阅:
OpenUI5 SDK - Demo Kit v2.0
updateFinished(oControlEvent)
This event is called after items binding and afterwards related DOM is updated.
Parameters:
{sap.ui.base.Event} oControlEvent
{sap.ui.base.EventProvider} oControlEvent.getSource
{object} oControlEvent.getParameters
{string} oControlEvent.getParameters.reason The reason of update. Possible values are "Binding", "Filter", "Sort", "Growing", "Change", "Refresh", "Context"
{int} oControlEvent.getParameters.actual Actual number of items.
{int} oControlEvent.getParameters.total The total count of bound items. This parameter can be used if "growing" feature is enabled.
Since:
1.16.3
关于javascript - setTimeout 的替代方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31747879/