我在SAPUI5
中編寫了一個前端程序,它應該允許用戶將數據(如字符或數字)輸入到表中,然後在單擊後讀取數據在「提交」按鈕上從sapui5的表中讀取用戶輸入
到目前爲止我所看到的是與從選定行獲取數據相關的所有內容。
我對這個領域真的很陌生,所以我很感激任何幫助!我正在使用sap.ui.commons.table.Table
。該表最初從JSON
文件獲取數據,但我已經完成了測試綁定。
//data definition:
var oPosData = [{PoItemI : "0010"}];
//Table:
var oTable = new sap.ui.table.Table("PoData",{
//title: "Positionsdetails",
visiblRowCount: 5,
firstVisibleRow: 3,
selectionMode: sap.ui.table.SelectionMode.Single
});
// For simplicity, i will just ad 1 column to the table. but i have more
//Positionsnummer:
var oColumn_PosNr = new sap.ui.table.Column("PosNr",{
label: new sap.ui.commons.Label({text: "Position"}),
//template: new sap.ui.commons.TextView().bindProperty("text", "Positionsnummer"),
template: Input1 = new sap.ui.commons.TextField("PosNrTF",{
key: "text",
value: "{PoItemI}"
}),
//sortProperty: "Positionsnummer",
//filterProperty: "Positionsnummer",
width: "200px"
});
//Input1.setValue("Bla"); Input1.getValue());
//Input1.attachChange(function(oEvent) {
var output = oEvent.getSource().getBindingContext().getPath();
alert('Text changed to : '+ output);
console.log(output)
});
oTable.addColumn(oColumn_PosNr);
//Create a model and bind the table rows to this model
var oModel_Item = new sap.ui.model.json.JSONModel();
oModel_Item.setData({modelData: oPosData});
oTable.setModel(oModel_Item);
oTable.bindRows("/modelData");
用這個表控件做錯了嗎?或者我在做綁定錯誤?當我嘗試閱讀它不起作用。
我也很難解開控件的綁定部分。
// Submit button
// I would be happy if this button prints me the value, that is stored in the
//table
var oButton1 = new sap.ui.commons.Button({
text : "Submit",
style: sap.ui.commons.ButtonStyle.Emph,
width: '50%',
//tooltip : "",
//press : function() {alert('Pressed me' +);}
press : function() {
var table_model = sap.ui.getCore().getControl("PoData").getModel();//.getPath();//.getPath();
var table_row = sap.ui.getCore().getControl("PoData").getRows()[1].getCells()[1];//.getValue();
var table_path = sap.ui.getCore().getControl("PosNrTF").getBindingContext(table_model);//.getPath();
var table_column_LABEL = oTable.getColumns()[0].getLabel().mProperties.text;
var table_column_template = oTable.getColumns()[0][1];//getBindingContext();
alert(table_column_LABEL);
alert(table_model);
alert(table_row);
alert(table_path);
alert(table_column_template);
},
layoutData : new sap.ui.layout.GridData({
indent: "L5 M5",
span: "L1 M6 S12"
})
});
我無法獲得存儲在列的模板部分中的值(如果存儲在該列中)。
我是否應該以不同的方式將行添加到表中而不是列中?我遇到了CustomData或內容但不知道如何使用它,如果這解決了問題?如果我只對用戶輸入的數據感興趣,或者綁定可以通過雙向綁定(不知道如何做到這一點)通過「自動更新值」來幫助我,我應該使用綁定嗎?
嗨nistv4n並感謝您的幫助! 當我打印/提醒它的值是空白的。我昨天晚上找到了一個解決方法,我將放在這裏。我所做的更改是首先讓我的表本身可編輯(而不僅僅是列)。我不知道這是如何影響它的,但是我添加了一個「添加」按鈕,在這裏我簡單地使用push來將新的初始數據推入我的數據字段, –