简体   繁体   English

如何在SAPUI5中重新加载页面?

[英]How to do reload a page in SAPUI5?

I want to do reload the page "Menu" after I save data with CRUD. 使用CRUD保存数据后,我想重新加载页面“菜单”。

var sUrl = "/sap/opu/odata/sap/ZGW_VISTORIA_SRV";
        var oModel = new sap.ui.model.odata.ODataModel(sUrl, true);
        var rota = this.getOwnerComponent().getRouter();
        var page = this;

        oModel.create('/vistoria', dados, null,
            function () {
                MessageBox.success('Cadastrado com sucesso!', {
                    onClose: function (sActionClicked) {
                        oStorage.clear();
                        oStorage.removeAll();
                        // oStorage.put("Save", {
                        //  isSave: true
                        // });
                        page.getView().exit();
                        page.getView().destroy();
                        // oStorage.get("Menu").menu.getModel().refresh(true);            
                        rota.navTo("Menu", false);
                        // window.location.reload(window.history.go(-3));
                        // sap.ui.getCore().byId("Menu").getModel().refresh(true);
                    }
                });
            },
            function () {
                MessageBox.error('Erro ao cadastrar o veiculo!');
            }
        );

I tried this in many ways, because I need to delete the information I save in forms. 我尝试了许多方法,因为我需要删除保存在表单中的信息。 So, can you help me? 那么,你能帮我吗?

First of all it'd be nice if u posted all your relevant code (the form too) next time, 首先,如果您下次发布所有与您相关的代码(也包括表单),那会很好,
but i think i understand what you want to do. 但是我想我知道你想做什么。
( resetting the form, NOT reloading the page ) 重置表单,不重新加载页面
(reloading the entire view would take way longer than just resetting the form ) (重新加载整个view将比重置form花费更长的时间)

The way to go is to bind the values of input / checkbox etc. that are inside your form in a model: 方法是绑定模型中表单内部的input / checkbox等值:

<Input
    id="someID"
    value="{urModel>/inputValue}"
    valueState="{vsModel>/vsInput}"
    valueStateText="{i18n>vstInput}"/>

then in your success methode or ur create you reset those values: 然后在成功方法或您创建的过程中重置这些值:

urRemoteModel.create("/urSet", oEntry, {
    success: function(oRetrievedResult) {
        this.getView().getModel(urModel).setProperty("/inputValue", "");
        //some other stuff

    }.bind(this),
        error: function(oError) {
        //error handling
     }
});

Sorry about my delay. 对不起,我延迟了。 I'm creating an app for checking trucks. 我正在创建一个用于检查卡车的应用程序。 When user to end the survey and saving, he will be redirect to page 'Menu'. 当用户结束调查并保存时,他将被重定向到“菜单”页面。

In that page, he can choice to do a new survey, clicking in the tile 'Cadastrar'. 在该页面中,他可以单击“ Cadastrar”图块来选择进行新的调查。 Here where there are the form that must clear: 这里有必须清除的表格:

<mvc:View xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" xmlns:form="sap.ui.layout.form" xmlns:core="sap.ui.core"
controllerName="com.sap.build.standard.formInspecaoDeVeiculos.controller.Identificacao">
<Page showHeader="true" title="Indenificação" showFooter="true" showNavButton="true" navButtonPress="_onPageNavButtonPress">
    <content>
        <Panel height="auto" width="auto" headerText="" expandable="false" expanded="true" expandAnimation="true" backgroundDesign="Solid"
            class="sapUiTinyMargin sapUiContentPadding">
            <content>
                <form:Form width="100%" editable="true" visible="true">
                    <form:title>
                        <core:Title text="Veículo" level="Auto"/>
                    </form:title>
                    <form:formContainers>
                        <form:FormContainer visible="true">
                            <form:formElements>
                                <form:FormElement visible="true">
                                    <form:label>
                                        <Label text="Veículo" design="Standard" width="100%" required="false" textAlign="Begin" textDirection="Inherit" visible="true"/>
                                    </form:label>
                                    <form:fields>
                                        <Input id="tratorInput" placeholder="Ex.: ABC1234" type="Text" showValueHelp="true" enabled="true" visible="true" width="auto"
                                            valueHelpOnly="false" maxLength="0" valueHelpRequest="handleValueHelp" suggestionItems="{/Veiculo}"
                                            value="{ path : '/placa', type : '.customPlacaType' }" valueLiveUpdate="{/ValueLiveUpdate}" liveChange="handleLiveChange">
                                            <suggestionItems>
                                                <core:Item text="{Placa}"/>
                                            </suggestionItems>
                                        </Input>
                                    </form:fields>
                                </form:FormElement>
                                <form:FormElement visible="true">
                                    <form:label>
                                        <Label text="Reboque(1)" design="Standard" width="100%" required="false" textAlign="Begin" textDirection="Inherit" visible="true"/>
                                    </form:label>
                                    <form:fields>
                                        <Input id="reboque1Input" placeholder="Ex.: ABC1234" type="Text" showValueHelp="true" enabled="true" visible="true" width="auto"
                                            valueHelpOnly="false" maxLength="0" valueHelpRequest="handleValueHelp" suggestionItems="{/Reboque}"
                                            value="{ path : '/placa', type : '.customPlacaType' }" valueLiveUpdate="{/ValueLiveUpdate}" liveChange="handleLiveChange">
                                            <suggestionItems>
                                                <core:Item text="{Placa}"/>
                                            </suggestionItems>
                                        </Input>
                                    </form:fields>
                                </form:FormElement>
                                <form:FormElement visible="true">
                                    <form:label>
                                        <Label text="Reboque(2)" design="Standard" width="100%" required="false" textAlign="Begin" textDirection="Inherit" visible="true"/>
                                    </form:label>
                                    <form:fields>
                                        <Input id="reboque2Input" placeholder="Ex.: ABC1234" type="Text" showValueHelp="true" enabled="true" visible="true" width="auto"
                                            valueHelpOnly="false" maxLength="0" valueHelpRequest="handleValueHelp" suggestionItems="{/Reboque}"
                                            value="{ path : '/placa', type : '.customPlacaType' }" valueLiveUpdate="{/ValueLiveUpdate}" liveChange="handleLiveChange">
                                            <suggestionItems>
                                                <core:Item text="{Placa}"/>
                                            </suggestionItems>
                                        </Input>
                                    </form:fields>
                                </form:FormElement>
                                <form:FormElement visible="true">
                                    <form:label>
                                        <Label text="Motorista" design="Standard" width="100%" required="false" textAlign="Begin" textDirection="Inherit" visible="true"/>
                                    </form:label>
                                    <form:fields>
                                        <Input id="motoristaInput" placeholder="Ex.: Nome do motorista" type="Text" showValueHelp="true" enabled="true" visible="true" width="auto"
                                            valueHelpOnly="false" maxLength="0" valueHelpRequest="handleValueHelp" suggestionItems="{/Motorista}" valueLiveUpdate="{/ValueLiveUpdate}"
                                            liveChange="handleLiveChange" value="{ path : '/Name1', type: '' }">
                                            <suggestionItems>
                                                <core:Item text="{Name1}"/>
                                            </suggestionItems>
                                        </Input>
                                    </form:fields>
                                </form:FormElement>
                                <form:FormElement visible="true">
                                    <form:label>
                                        <Label text="CPF" design="Standard" width="100%" required="false" textAlign="Begin" textDirection="Inherit" visible="true"/>
                                    </form:label>
                                    <form:fields>
                                        <Input id="cpfInput" placeholder="Ex.: 00000000000" type="Text" showValueHelp="true" enabled="true" visible="true" width="auto"
                                            valueHelpOnly="false" maxLength="0" valueHelpRequest="handleValueHelp" suggestionItems="{/Motorista}" valueLiveUpdate="{/ValueLiveUpdate}"
                                            liveChange="handleLiveChange">
                                            <suggestionItems>
                                                <core:Item text="{Stcd2}"/>
                                            </suggestionItems>
                                        </Input>
                                    </form:fields>
                                </form:FormElement>
                            </form:formElements>
                            <form:title/>
                        </form:FormContainer>
                    </form:formContainers>
                    <form:layout>
                        <form:ResponsiveGridLayout adjustLabelSpan="false" columnsL="2" labelSpanL="3" columnsM="1" labelSpanM="2" labelSpanS="12"/>
                    </form:layout>
                </form:Form>
            </content>
        </Panel>
    </content>
    <footer>
        <OverflowToolbar width="100%" height="auto" design="Auto" enabled="true" visible="true">
            <content>
                <ToolbarSpacer width=""/>
                <Button text="" type="Emphasized" icon="sap-icon://navigation-right-arrow" iconFirst="true" width="auto" enabled="true" visible="true"
                    iconDensityAware="false" press="_onContinue"/>
            </content>
        </OverflowToolbar>
    </footer>
    <headerContent/>
    <subHeader/>
    <customHeader/>
</Page>

In my input i'm set de property value with "path: /placa" because I use an assitent for seach. 在我的输入中,我使用“ path:/ placa”设置了属性值,因为我使用辅助来进行搜索。 In the next page 'Conclusao', where the user to finalize survey. 在下一页“ Conclusao”中,用户可以在其中完成调查。 My question: how I can to acess a Model from a page in onother page? 我的问题:如何从其他页面上的页面访问模型?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM