在UI5中编辑/更新绑定数据时,不会发生数据绑定

问题描述 投票:0回答:1

我有一个主 - 详细页面,它有一个克隆按钮。单击克隆按钮时,第一个列表项的数据将放入模型(detailModel - 在component.js中声明)并打开一个新屏幕。该列表项的数据绑定到某些输入字段。当更新/删除任何输入字段,然后用户导航回来而不保存并再次出现在该页面上时,更新/删除的字段将保持空白。我希望这些数据能够进入那个早先出现的领域,但它仍然是空白的。我模型中的数据也没有变化。以下是代码:

Component.js:

this.detailModel = new sap.ui.model.json.JSONModel();
        this.detailModel.setDefaultBindingMode(sap.ui.model.BindingMode.OneWay);
            sap.ui.getCore().setModel(this.detailModel, "detailModel");

Controller.js:

        /*eslint-disable no-console, no-alert */
    sap.ui.define([
        "sap/ui/core/mvc/Controller",
        "sap/ui/model/json/JSONModel",
        "hmel/TravelandGuestHouse/controller/formatter",
        "sap/m/MessageToast",
        "sap/m/MessageBox",
        "sap/m/Button",
        "sap/m/Dialog",
        "sap/m/Text",
        'sap/m/Label',
        'sap/m/TextArea'
    ], function (Controller, JSONModel, formatter, MessageToast, MessageBox, Button, Dialog, Text, Label, TextArea) {
        "use strict";
        return Controller.extend("hmel.TravelandGuestHouse.controller.CloneTravelRequest", {

            onInit: function () {
                this.router = sap.ui.core.UIComponent.getRouterFor(this);
                //for cloning request
                this.detailModel = sap.ui.getCore().getModel("detailModel");
                this.getView().setModel(this.detailModel, "detailModel");
                //for sending data to guest house screen
                this.getView().byId("date").setDateValue(new Date());
                this.router.attachRoutePatternMatched(this._handleRouteMatched, this);
            },

            _handleRouteMatched: function (evt) {
                if (evt.getParameter("name") !== "CloneTravelRequest") {
                    return;
                }

                this.getView().invalidate();

                    var that = this;

                //fetching Train Names
                $.ajax({
                    url: "/Non_sap_create_requests/odata/TravelPrpTrainDetails",
                    method: "GET",
                    dataType: "json",
                    success: function (data) {
                        that.getView().getModel("Model").setProperty("/TravelPrpTrainDetails", data.value);
                        var tempModel = that.getView().getModel("detailModel");
                        var train = tempModel.getData().TrainName;
                        var trainKey = formatter.pickTrainKeyFromModel(data.value, train);
                        that.getView().byId("trainName").setSelectedKey(trainKey);
                        that.setLocations();
                        var nameofPass = tempModel.getData().NameOfPsngr;
                        if (nameofPass === "" || nameofPass === null) {
                            that.getView().byId("nameOfP").setValue(tempModel.getData().Requestee);
                        }
                    },
                    error: function (err) {
                        console.log(err.message);

                    }
                });

                var fdate = new Date();
                this.getView().byId("date").setDateValue(new Date());
                this.getView().byId("date").setMinDate(fdate);
            }



        });
    });
javascript model-view-controller model sapui5
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.