0

我正在寻求你的帮助。我创建了一个网络应用程序。在这里我可以创建一个表和控制条目。现在我很沮丧,因为我不知道如何将这个表保存到数据库中。这是保存功能:

onSave: function() {
    //Create all the records added to table via Json model
    var oTable = this.getView().byId("packItem");
    // Get the table Model
    var oModel = oTable.getModel();
    // Get Items of the Table
    var aItems = oTable.getItems();
    // Define an empty Array
    var itemData = [];
    for (var iRowIndex = 0; iRowIndex < aItems.length; iRowIndex++) {
        var l_material = oModel.getProperty("Material", aItems[iRowIndex].getBindingContext());
        var l_batch = oModel.getProperty("Batch", aItems[iRowIndex].getBindingContext());
        var l_quantity = oModel.getProperty("Quantity", aItems[iRowIndex].getBindingContext());
        var l_unit = oModel.getProperty("Unit", aItems[iRowIndex].getBindingContext());
        itemData.push({
            Batch: l_batch,
            Matnr: l_material,
            Qty: l_quantity,
            Uom: l_unit,
        });
    }
    // Get the values of the header input fields
    var ComCode = this.getView().byId("inputCC").getValue();
    var Plant = this.getView().byId("inputPlant").getValue();

    // Create one emtpy Object
    var oEntry1 = {};
    oEntry1.Bukrs = ComCode;
    oEntry1.Werks = Plant;

    var oModel1 = new sap.ui.model.odata.ODataModel(""); // Define the model
    this.getView().setModel(oModel1);// set the model
    oModel1.setHeaders({"X-Requested-With": "X"});

    oModel1.create("", oEntry1, { // Call the OData Service (.creat Function)
        success: function(oData, oResponse) {

        },
        error: function(oError) {
            alert("Failure - OData Service could not be called. Please check the Network Tab at Debug.");
        }
    });
}
4

1 回答 1

1

UI5 应用程序是客户端应用程序。因此,您创建的表只是 UI 表。数据的一个很好的表示。但不要将它与数据库表混合。您的数据库由您的后端系统管理。这意味着您应该有一个系统在您的服务器的任何端口进行侦听,以便它可以处理您的请求并操作数据库。

通常 UI5 应用程序通过 OData 调用或 AJAX 调用将数据发送到后端端点。但两者都只是在 HTTP 请求的正文或标头中将一堆数据发送到特定 URL 的协议。

要在您的数据库中创建一个新表(我猜它是一个 SQL 数据库),您应该在您的服务器中公开一个服务,该服务在您调用该服务时对您的数据库执行 CREATE SQL 查询。但这根本不是 UI5。这是后端人员,这取决于您拥有哪种后端,哪种数据库等

于 2018-08-11T06:20:04.990 回答