我是SAPUI5的新手。我想每10秒重新加载一次json服务。我的控制器代码是。
modelServices :function()
{
var oModeldata = new sap.ui.model.json.JSONModel("https://my-example.com/status/");
this.getView().setModel(oModeldata, "datalake");
},`
我从控制器的init函数调用此方法,我的视图是
<TileContainer id="lstDataLakeView" tiles="{datalake>/collectionStatus}">
<CustomTile class="sapMTile" borderVisible="true">
<l:VerticalLayout class="sapUiContentPadding" width="100%">
<l:content>
<core:Icon src="sap-icon://database" class="size2" color="#55acee">
<core:layoutData>
<FlexItemData growFactor="1"/>
</core:layoutData>
</core:Icon>
<FlexBox alignItems="End" justifyContent="End">
<items>
<Text text="Size {datalake>size}" tooltip="Size"/>
</items>
</FlexBox>
</l:content>
</l:VerticalLayout>
</CustomTile>
</TileContainer>
我想每隔10秒刷新一次这个图块。我知道javascript中有一个方法setTimeInterval(函数,时间);或者setTimeOut(),但我现在确定如何使用它。
答案 0 :(得分:3)
请注意不要在其回拨中拨打$.ajax({
type: 'GET',
url: '/path-to-my/image.png',
data: null,
success: function(data){
alert('horray! 200 status code!');
// convert to base64; add to img.src # btoa(data)
document.querySelector("#hlogo img").src = "data:;base64,"+ data;
},
error:function (xhr, ajaxOptions, thrownError){
switch (xhr.status) {
case 400:
// Take action, referencing xhr.responseText as needed.
case 404:
// Take action, referencing xhr.responseText as needed.
case 500:
// Take action, referencing xhr.responseText as needed.
}
});
。否则,您将在第一次回调后运行2个计时器,并且每10秒加倍一次。
如果您的视图不再显示,还应确保停止计时器。
dataurl := "data:" [ mediatype ] [ ";base64" ] "," data
mediatype := [ type "/" subtype ] *( ";" parameter )
data := *urlchar
parameter := attribute "=" value
答案 1 :(得分:0)
modelServices :function()
{
var that = this;
var oModeldata = new sap.ui.model.json.JSONModel("https://my-example.com/status/");
this.getView().setModel(oModeldata, "datalake");
setInterval( function() { that.modelServices (); }, 10000 );
},