我正在使用响应式表(sap.m.Table),我想知道当单击表上的Delete按钮时如何在控制器中获取行值。我正在尝试在函数onGaDelete和onGakDelete中获取行值。
这是我的查看代码。
<mvc:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m"
controllerName="ariba.so.kaaguidedassistance.controller.GuidedAssistance" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:f="sap.uxap">
<f:ObjectPageLayout id="ObjectPageLayout">
<f:headerTitle>
<f:ObjectPageHeader objectTitle="{title>/pageTitle}">
<f:actions>
<f:ObjectPageHeaderActionButton text="save" hideIcon="true" hideText="false" press="onSubmit"/>
<f:ObjectPageHeaderActionButton text="edit" hideIcon="true" hideText="false" press="onEdit"/>
<f:ObjectPageHeaderActionButton text="cancel edit" hideIcon="true" hideText="false" press="onCancelEdit"/>
</f:actions>
</f:ObjectPageHeader>
</f:headerTitle>
<f:sections>
<f:ObjectPageSection id="gaqaId" title="Guided Assistance Qa Flow">
<f:subSections>
<f:ObjectPageSubSection id="gaqaSS" title=" ">
<f:blocks>
<Table id="gaTable" items="{path: 'garows>/flow'}" mode="Delete" delete="onGaDelete">
<headerToolbar>
<OverflowToolbar>
<content>
<Title text="Guided Assistance Qa" level="H2"/>
</content>
</OverflowToolbar>
</headerToolbar>
<columns>
<Column width="6em">
<Text text="ID"/>
</Column>
<Column width="10em">
<Text text="value_long"/>
</Column>
<Column width="8em">
<Text text="Type"/>
</Column>
<Column width="8em">
<Text text="Action"/>
</Column>
<Column width="8em">
<Text text="Button1"/>
</Column>
<Column width="8em">
<Text text="Button2"/>
</Column>
<Column width="8em">
<Text text="Button3"/>
</Column>
<Column width="10em">
<Text text="Button4"/>
</Column>
<Column width="8em">
<Text text="Button5"/>
</Column>
<Column width="8em">
<Text text="Button6"/>
</Column>
<Column width="3em">
<Text text="Active_Flag"/>
</Column>
</columns>
<items>
<ColumnListItem>
<cells>
<Text text="{garows>ID}"/>
<Text text="{garows>value_long}"/>
<Text text="{garows>Type}"/>
<Text text="{garows>Action}"/>
<Text text="{garows>Button1}"/>
<Text text="{garows>Button2}"/>
<Text text="{garows>Button3}"/>
<Text text="{garows>Button4}"/>
<Text text="{garows>Button5}"/>
<Text text="{garows>Button6}"/>
<Text text="{garows>Active_Flag}"/>
</cells>
</ColumnListItem>
</items>
</Table>
</f:blocks>
</f:ObjectPageSubSection>
</f:subSections>
</f:ObjectPageSection>
<f:ObjectPageSection id="gakqaId" title="Keywords">
<f:subSections>
<f:ObjectPageSubSection id="gakqaSS" title=" ">
<f:blocks>
<Table id="gakTable" items="{path: 'gakrows>/flow'}" mode="Delete" delete="onGakDelete">
<headerToolbar>
<OverflowToolbar>
<content>
<Title text="Guided Assistance Keywords Qa" level="H2"/>
</content>
</OverflowToolbar>
</headerToolbar>
<columns>
<Column width="8em">
<Text text="Flow_ID"/>
</Column>
<Column width="10em">
<Text text="Keywords"/>
</Column>
<Column width="10em">
<Text text="Intersection1"/>
</Column>
<Column width="10em">
<Text text="Intersection2"/>
</Column>
<Column width="3em">
<Text text="Logic_Group"/>
</Column>
<Column width="3em">
<Text text="Logic_Order"/>
</Column>
<Column width="3em">
<Text text="Points"/>
</Column>
<Column width="3em">
<Text text="ID"/>
</Column>
</columns>
<items>
<ColumnListItem>
<cells>
<Text text="{gakrows>Flow_ID}"/>
<Text text="{gakrows>Keywords}"/>
<Text text="{gakrows>Intersection1}"/>
<Text text="{gakrows>Intersection2}"/>
<Text text="{gakrows>Logic_Group}"/>
<Text text="{gakrows>Logic_Order}"/>
<Text text="{gakrPointsows>Points}"/>
<Text text="{gakrows>ID}"/>
</cells>
</ColumnListItem>
</items>
</Table>
</f:blocks>
</f:ObjectPageSubSection>
</f:subSections>
</f:ObjectPageSection>
</f:sections>
</f:ObjectPageLayout>
</mvc:View>
这是我的控制器代码。
/*global location history */
sap.ui.define([
"ariba/so/kaaguidedassistance/controller/BaseController",
"sap/ui/model/json/JSONModel",
"sap/m/MessageToast",
"sap/m/ColumnListItem",
"sap/m/TextArea",
"sap/m/Text"
], function (BaseController, JSONModel, MessageToast, ColumnListItem, TextArea, Text) {
"use strict";
return BaseController.extend("ariba.so.kaaguidedassistance.controller.GuidedAssistance", {
onInit: function () {
this.getRouter().getRoute("guidedAssistance").attachMatched(this.onRouteMatched, this);
},
onRouteMatched: function (oEvent) {
var oParameters = {
"ID": oEvent.getParameter("arguments").flowId,
"gaorgak": "GA"
};
this.getView().setModel(new JSONModel({
"pageTitle": oParameters.ID
}), "title");
$.ajax({
url: "private url",
type: "POST",
data: JSON.stringify(oParameters),
contentType: "application/json",
success: function (data) {
this.getView().setModel(new JSONModel(data), "garows");
}.bind(this),
error: function (e) {
MessageToast.show(e.statusText);
}
});
oParameters.gaorgak = "GAK";
$.ajax({
url: "private url",
type: "POST",
data: JSON.stringify(oParameters),
contentType: "application/json",
success: function (data) {
this.getView().setModel(new JSONModel(data), "gakrows");
}.bind(this),
error: function (e) {
MessageToast.show(e.statusText);
}
});
},
onEdit: function () {
var oTable = this.byId("gaTable");
oTable.setMode("None");
oTable.bindItems({
path: "garows>/flow",
template: new ColumnListItem({
cells: [
new Text({
text: "{garows>ID}"
}),
new TextArea({
value: "{garows>value_long}",
growing: true,
growingMaxLines: 7
}),
new TextArea({
value: "{garows>Type}"
}),
new TextArea({
value: "{garows>Action}"
}),
new TextArea({
value: "{garows>Button1}"
}),
new TextArea({
value: "{garows>Button2}"
}),
new TextArea({
value: "{garows>Button3}"
}),
new TextArea({
value: "{garows>Button4}"
}),
new TextArea({
value: "{garows>Button5}"
}),
new TextArea({
value: "{garows>Button6}"
}),
new TextArea({
value: "{garows>Active_Flag}"
})
]
}),
key: "ID"
}).setKeyboardMode("Edit");
oTable = this.byId("gakTable");
oTable.setMode("None");
oTable.bindItems({
path: "gakrows>/flow",
template: new ColumnListItem({
cells: [
new Text({
text: "{gakrows>Flow_ID}"
}),
new TextArea({
value: "{gakrows>Keywords}",
growing: true,
growingMaxLines: 7
}),
new TextArea({
value: "{gakrows>Intersection1}",
growing: true,
growingMaxLines: 7
}),
new TextArea({
value: "{gakrows>Intersection2}",
growing: true,
growingMaxLines: 7
}),
new TextArea({
value: "{gakrows>Logic_Group}"
}),
new TextArea({
value: "{gakrows>Logic_Order}"
}),
new TextArea({
value: "{gakrows>Points}"
}),
new Text({
text: "{gakrows>ID}"
})
]
}),
key: "ID"
}).setKeyboardMode("Edit");
},
onCancelEdit: function () {
var oTable = this.byId("gaTable");
oTable.setMode("Delete");
oTable.bindItems({
path: "garows>/flow",
template: new ColumnListItem({
cells: [
new Text({
text: "{garows>ID}"
}),
new Text({
text: "{garows>value_long}"
}),
new Text({
text: "{garows>Type}"
}),
new Text({
text: "{garows>Action}"
}),
new Text({
text: "{garows>Button1}"
}),
new Text({
text: "{garows>Button2}"
}),
new Text({
text: "{garows>Button3}"
}),
new Text({
text: "{garows>Button4}"
}),
new Text({
text: "{garows>Button5}"
}),
new Text({
text: "{garows>Button6}"
}),
new Text({
text: "{garows>Active_Flag}"
})
]
}),
key: "ID"
}).setKeyboardMode("Navigation");
oTable = this.byId("gakTable");
oTable.setMode("Delete");
oTable.bindItems({
path: "gakrows>/flow",
template: new ColumnListItem({
cells: [
new Text({
text: "{gakrows>Flow_ID}"
}),
new Text({
text: "{gakrows>Keywords}"
}),
new Text({
text: "{gakrows>Intersection1}"
}),
new Text({
text: "{gakrows>Intersection2}"
}),
new Text({
text: "{gakrows>Logic_Group}"
}),
new Text({
text: "{gakrows>Logic_Order}"
}),
new Text({
text: "{gakrows>Points}"
}),
new Text({
text: "{gakrows>ID}"
})
]
}),
key: "ID"
}).setKeyboardMode("Navigation");
},
onSubmit: function () {
var oGak = this.getModel("gakrows").getData().flow;
var oData = [];
oData.push(this.getModel("garows").getData().flow[0]);
for (var i = 0; i < oGak.length; i++) {
oData.push(oGak[i]);
}
this.getOwnerComponent().getModel("guidedAssistance").
loadData("private url", JSON.stringify(oData),
true, "POST", true, false, {});
},
onGaDelete: function (oEvent) {
//trying to get the row values here.
},
onGakDelete: function (oEvent) {
//trying to get the row values here.
}
});
});
预期结果是在控制器中获取行值。
答案 0 :(得分:2)
delete
api事件提供了"listItem"
参数,通过该参数我们可以获取被单击的项目控件以及通过其上下文绑定的数据。例如:
<Table xmlns="sap.m"
mode="Delete"
delete=".onItemDelete"
>
<!-- ... -->
</Table>
onItemDelete: function(event) {
const itemToDelete = event.getParameter("listItem"); // clicked ColumnListItem
const context = itemToDelete.getBindingContext(/*modelName*/);
// get row values via context.getProperty(<propertyName>); E.g.:
const boundId = context.getProperty("ID");
// or get the whole object:
const boundObject = context.getObject(); // returns {ID: "...", ...}
},