通过SAPUI5应用程序在数据库中创建新记录后,未调用格式化程序。表格会刷新,新的数据可见,但按钮未正确启用。
查看图片。
以下是一些代码:
刷新代码:
this.byId("Table").getBinding("items").refresh();
格式化程序:
blockedFormatterFrom: function (value) {
var datum = new Date();
var dateString = value.substr(6, 4) + "." + value.substr(3, 2) + "." + value.substr(0, 2);
if (new Date(dateString) < datum) {
editable_from = false;
} else {
editable_from = true;
}
return value;
},
blockedFormatterTo: function (value) {
var datum = new Date();
var dateString = value.substr(6, 4) + "." + value.substr(3, 2) + "." + value.substr(0, 2);
if (new Date(dateString) < datum) {
editable_to = false;
} else {
editable_to = true;
}
return value;
},
editableFormatterEdit: function (value) {
if (editable_from && editable_to) {
return true;
} else {
return false;
}
},
editableFormatterDelete: function (value) {
if (editable_to) {
return true;
} else {
return false;
}
}
XML视图
<mvc:View xmlns:mvc="sap.ui.core.mvc" xmlns:html="http://www.w3.org/1999/xhtml" xmlns="sap.m" controllerName="buhler.Order_Matrix.controller.View_ZSCORDERING" displayBlock="true">
<App id="idAppControl">
<pages><Page title="{i18n>title}">
<content>
<Table noDataText="Keine Daten gefunden" items="{ path: '/ZSCORDERINGSet'}" id="Table" >
<headerToolbar>
<Toolbar class="sapMTBHeader">
<Button tooltip="View Sort Settings" icon="sap-icon://sort" press="handleSortButtonPressed"/>
<Button tooltip="View Filter Settings" icon="sap-icon://filter" press="handleFilterButtonPressed"/>
<FlexBox class="alertsTablePagination" justifyContent="SpaceAround">
<Button id="policyChangeBtn" class="alertbutton" text="New" enabled="true" press="onNewPress"/>
</FlexBox>
<content>
<SearchField width="50%" search="onFilterMatrix" placeholder="Suche Verkaufsorganisation"/>
</content>
</Toolbar>
</headerToolbar>
<infoToolbar>
<Toolbar id="vsdFilterBar" visible="false">
<Text id="vsdFilterLabel"/>
</Toolbar>
</infoToolbar>
<items>
<ColumnListItem type="Active" id="item0">
<cells>
<Text text="{Vkorg}" id="text3"/>
<Text text="{ZzscSpSas}" id="text4"/>
<Text text="{path:'ValdFrom', type:'sap.ui.model.odata.type.DateTime', constraints: {displayFormat: 'Date'}, cet: true, formatter: '.blockedFormatterFrom'}" id="text5"/>
<Text text="{path:'ValdTo', type:'sap.ui.model.odata.type.DateTime', constraints: {displayFormat: 'Date'}, cet: true, formatter: '.blockedFormatterTo'}" id="text6"/>
<Text text="{ZzscIcSas}" id="text7"/></cells>
<Button text="Edit" press="onEditPress" enabled="{path: 'a', formatter: '.editableFormatterEdit'}"/>
<Button text="Delete" press="onDeletePress" enabled="{path: 'a', formatter: '.editableFormatterDelete'}"/>
</ColumnListItem>
</items>
<columns>
<Column id="column1">
<header>
<Label text="Verkaufsorganisation" id="label0"/>
</header>
</Column>
<Column id="column2">
<header>
<Label text="SAS Supplier" id="label1"/>
</header>
</Column>
<Column id="column3">
<header>
<Label text="Gültig ab" id="label2"/>
</header>
</Column>
<Column id="column4">
<header>
<Label text="Gültig bis" id="label3"/>
</header>
</Column>
<Column id="column5">
<header>
<Label text="SAS Intercompany" id="label4"/>
</header>
</Column>
<Column>
<header>
<Label text="Edit"/>
</header>
</Column>
<Column>
<header>
<Label text="Delete"/>
</header>
</Column>
</columns>
</Table>
</content>
</Page>
</pages>
</App>
如何刷新表格并运行格式化程序?
答案 0 :(得分:1)
下面的这段代码是否解决了您的问题?
this.byId("Table").setModel(oModel);
this.getView().byId('Table').rerender();
我试图复制您的问题,但没有遇到。刷新模型后,列表将被更新,并且我的自定义格式器也会被触发。参见以下示例:
manifest.json
"dataSources": {
"mainService": {
"uri": "/sap/opu/odata/sap/ZHR_MY_WORKSCHEDULE_SRV/",
"type": "OData",
"settings": {
"odataVersion": "2.0",
"localUri": "localService/metadata.xml"
}
}
}
......
"models": {
"": {
"dataSource": "mainService",
"settings": {
"defaultCountMode": "Inline"
}
}
}
查看
<Page title="{i18n>title}">
<headerContent>
<Button icon="sap-icon://refresh" tooltip="Share" press="onRefresh" />
</headerContent>
<content>
<List items="{/WorkSched_PendingSet}">
<StandardListItem
title="{EmpName}"
description="{
path : 'Position',
formatter : '.formatter.fnFormatDescription'
}"
type="Active">
</StandardListItem>
</List>
</content>
</Page>
控制器
return Controller.extend("com.demoDemo.controller.View1", {
formatter : Formatter,
onRefresh : function() {
this.getView().getModel().refresh();
}
});
答案 1 :(得分:0)
您还可以共享XML视图吗?
尝试使用 headers: {
'Access-Control-Allow-Origin': '*',
"Content-type": "application/json; charset=UTF-8",
'mode':'no-cors',
},
答案 2 :(得分:0)
this.byId("Table").setModel(oModel);
this.getView().byId('Table').rerender();
将模型设置为表格并调用函数rerender()