简体   繁体   English

在UI5中编辑/更新绑定的数据时未发生数据绑定

[英]Data binding not happening when the binded data is edited/updated in UI5

I have a master-detail page which has a clone button. 我有一个包含克隆按钮的主从页面。 On clicking the clone button, the data of the first list item is put into a model (detailModel - which is declared in component.js) and a new screen is opened. 单击克隆按钮后,第一个列表项的数据被放入模型(detailModel-在component.js中声明),并打开一个新屏幕。 The data of that list item is binded to some input fields. 该列表项的数据绑定到某些输入字段。 When any of that input field is updated/erased and then user navigates back without saving it and comes again on that page, that updated/erased field stays blank. 当该输入字段中的任何一个被更新/擦除后,用户又导航而不保存它并再次出现在该页面上时,该更新/擦除的字段将保持空白。 I want that data to come in that field which was coming earlier but it is coming blank. 我希望这些数据进入较早出现的那个字段,但现在为空白。 Data in my model is also not changing. 我模型中的数据也没有改变。 Below is the code : 下面是代码:

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



        });
    });

If you can change to an oDataModel you can use the resetChanges method. 如果可以更改为oDataModel ,则可以使用resetChanges方法。

If you cant, you `ll have to do it a little bit more manually. 如果不能的话,您将不得不手动进行一些操作。 Once the new windows pops up save the data the user will change and if he cancels it restore the saved data on the jsonDataModel. 一旦弹出新窗口,保存数据,用户将更改,如果取消,则将保存的数据恢复到jsonDataModel上。

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

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