UI5:刷新 Table 包含相对时间戳,模型中没有更改
UI5: refresh Table containing relative timestamp without changes in the Model
问题
我目前正在处理包含 Table 的视图。其中一列是table中元素最后一次更新的相对时间戳(Last Update: 6 seconds ago),使用
<Text text="{
path: 'lastUpdate',
type: 'sap.ui.model.type.DateTime',
formatOptions: {
source: {pattern: 'yyyy-MM-ddTHH:mm:ss.SSSZZZZ'},
relative: true,
relativeScale: 'auto'
}
}"/>
到现在为止,我每次获取请求时都会从后端传输当前模型,因此视图总是在每次更新时使用模型更新自身。但是,为了节省带宽,我决定在调用中加入 If-Modified-Since
条件,这样后端只会向我发送自上次调用以来实际更新过的模型,否则 returns 304.
然而,我现在遇到的问题是,由于模型不再被替换,视图同样不会更新,最近的事件将停留在例如“Last Update: 15 seconds ago”可能是几分钟;直到有新的更新。
问题
我正在寻找一个函数,它告诉视图(甚至只是 table 或特定列)根据新的当前时间刷新其内容,即使基础数据没有改变.
到目前为止,我找到并尝试了
that.byId("myTable").getBinding("items").refresh();
但这并没有做任何事情,我想是因为它仍然认识到数据没有改变。
编辑:按照公认的答案,调用 that.getView().getModel().refresh(true);
确实产生了预期的结果。
您是否尝试过使用.refresh(true)
sap.ui.model.odata 的 DemoKit 展示。v2.ODataListBinding:
refresh(bForceUpdate?, sGroupId?) : void
bForceUpdate 的意思是“即使没有更改数据也更新绑定控件”
问题
我目前正在处理包含 Table 的视图。其中一列是table中元素最后一次更新的相对时间戳(Last Update: 6 seconds ago),使用
<Text text="{
path: 'lastUpdate',
type: 'sap.ui.model.type.DateTime',
formatOptions: {
source: {pattern: 'yyyy-MM-ddTHH:mm:ss.SSSZZZZ'},
relative: true,
relativeScale: 'auto'
}
}"/>
到现在为止,我每次获取请求时都会从后端传输当前模型,因此视图总是在每次更新时使用模型更新自身。但是,为了节省带宽,我决定在调用中加入 If-Modified-Since
条件,这样后端只会向我发送自上次调用以来实际更新过的模型,否则 returns 304.
然而,我现在遇到的问题是,由于模型不再被替换,视图同样不会更新,最近的事件将停留在例如“Last Update: 15 seconds ago”可能是几分钟;直到有新的更新。
问题
我正在寻找一个函数,它告诉视图(甚至只是 table 或特定列)根据新的当前时间刷新其内容,即使基础数据没有改变.
到目前为止,我找到并尝试了
that.byId("myTable").getBinding("items").refresh();
但这并没有做任何事情,我想是因为它仍然认识到数据没有改变。
编辑:按照公认的答案,调用 that.getView().getModel().refresh(true);
确实产生了预期的结果。
您是否尝试过使用.refresh(true)
sap.ui.model.odata 的 DemoKit 展示。v2.ODataListBinding:
refresh(bForceUpdate?, sGroupId?) : void
bForceUpdate 的意思是“即使没有更改数据也更新绑定控件”