table 刷新后未调用格式化程序

Formatter not called after table refresh

在我通过我的 SAPUI5 应用程序在数据库中创建新记录后,没有调用格式化程序。 Table 刷新并且新数据可见,但按钮未正确启用。

查看图片。

这是一些代码:

刷新代码:

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>

如何刷新 Table 和 运行 格式化程序?

您能否也分享 XML 观点? 尝试使用 this.byId("Table").getBinding("items").refresh(true);

强制刷新
this.byId("Table").setModel(oModel);
this.getView().byId('Table').rerender();

将模型设置为 table 并调用函数 rerender()

下面这段代码是否解决了您的问题?

this.byId("Table").setModel(oModel);
this.getView().byId('Table').rerender();

我尝试重现您的问题,但没有遇到。刷新模型后,list 将被更新,并且我的自定义格式化程序将被触发。请参阅以下示例:

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();
    }
});