SAPUI5:Select Table 中的行项目不起作用
SAPUI5 : Select Line item in Table not working
我构建了一个如下所示的 XML 片段。
<core:FragmentDefinition xmlns="sap.m"
xmlns:fb="sap.ui.comp.filterbar" xmlns:core="sap.ui.core">
<Dialog stretch="false" title="Select User" showHeader="true">
<content>
<fb:FilterBar reset="onReset" search="onSearch"
advancedMode="true">
<fb:filterItems>
<fb:FilterItem id="searchField" name="userSeacrch">
<fb:control>
<SearchField width="100%" id="searchUser" showSearchButton="false"/>
</fb:control>
</fb:FilterItem>
</fb:filterItems>
<fb:filterGroupItems>
<fb:FilterGroupItem groupName="G1" id="fname1" idgroupTitle="Group1" name="A" label="First Name" labelTooltip="First Name">
<fb:control>
<Input type="Text" id="fname"/>
</fb:control>
</fb:FilterGroupItem>
<fb:FilterGroupItem groupName="G1" id="lname1" groupTitle="Group1" name="B" label="Last Name" labelTooltip="Last Name">
<fb:control>
<Input type="Text" id="lname"/>
</fb:control>
</fb:FilterGroupItem>
<fb:FilterGroupItem groupName="G1" id="department1" groupTitle="Group1" name="C" label="Department" labelTooltip="Department">
<fb:control>
<Input type="Text" id="department"/>
</fb:control>
</fb:FilterGroupItem>
</fb:filterGroupItems>
</fb:FilterBar>
<Table id="idF4" inset="true"
backgroundDesign="Translucent"
visibleRowCount="5"
noDataText="No data exists" >
<headerToolbar>
<Toolbar>
<Label text="User(s)"></Label>
</Toolbar>
</headerToolbar>
<columns>
<Column>
<Text text="User" type="Navigation"/>
</Column>
<Column minScreenWidth="small" popinDisplay="Inline" demandPopin="true">
<Text text="First Name" type="Navigation" />
</Column>
<Column minScreenWidth="small" popinDisplay="Inline" demandPopin="true">
<Text text="Last Name" type="Navigation" />
</Column>
<Column>
<Text text="Department" type="Navigation"/>
</Column>
</columns>
<items>
<ColumnListItem type="Navigation" selected="true" press="handleLineItemPress">
<cells>
<Text />
<Text />
<Text />
<Text "/>
</cells>
</ColumnListItem>
</items>
</Table>
</content>
<beginButton>
<Button text="Cancel" press="onCloseDialog" />
</beginButton>
</Dialog>
</core:FragmentDefinition>
我没有动态绑定数据。而是遵循以下方法。
for (var i = 0; i < oData.results.length; i++) {
oEntry.Bname = oData.results[i].Bname;
oEntry.Name1 = oData.results[i].Name1;
oEntry.Name2 = oData.results[i].Name2;
oEntry.Department = oData.results[i].Department;
var oTemplate = new sap.m.ColumnListItem(
{
cells : [
new sap.m.Text({
text : oEntry.Bname
}),
new sap.m.Text({
text : oEntry.Name1
}),
new sap.m.Text({
text : oEntry.Name2
}),
new sap.m.Text({
text : oEntry.Department
}) ] } );
oTable.addItem(oTemplate);
}
现在,当我 select 来自此 table 的条目时,不会触发事件 "press"。
我也有一个控制器代码。
handleLineItemPress : function(oEvent){
var currentRowContext = oEvent.getParameter("rowContext");
},
真的吗?....
先好好看看你的代码。
您定义了一个 table -- 没有数据绑定 -- 所以它只有一个 ColumnListItem
并分配了一个 press
事件。
在您的代码中,您要向 table 添加更多 ColumnListItem
,而这些没有分配 press
事件。
现在您要问为什么这些行的 press
事件不起作用? ;-)
(附带说明一下,您不使用数据绑定的原因是什么?)
我构建了一个如下所示的 XML 片段。
<core:FragmentDefinition xmlns="sap.m"
xmlns:fb="sap.ui.comp.filterbar" xmlns:core="sap.ui.core">
<Dialog stretch="false" title="Select User" showHeader="true">
<content>
<fb:FilterBar reset="onReset" search="onSearch"
advancedMode="true">
<fb:filterItems>
<fb:FilterItem id="searchField" name="userSeacrch">
<fb:control>
<SearchField width="100%" id="searchUser" showSearchButton="false"/>
</fb:control>
</fb:FilterItem>
</fb:filterItems>
<fb:filterGroupItems>
<fb:FilterGroupItem groupName="G1" id="fname1" idgroupTitle="Group1" name="A" label="First Name" labelTooltip="First Name">
<fb:control>
<Input type="Text" id="fname"/>
</fb:control>
</fb:FilterGroupItem>
<fb:FilterGroupItem groupName="G1" id="lname1" groupTitle="Group1" name="B" label="Last Name" labelTooltip="Last Name">
<fb:control>
<Input type="Text" id="lname"/>
</fb:control>
</fb:FilterGroupItem>
<fb:FilterGroupItem groupName="G1" id="department1" groupTitle="Group1" name="C" label="Department" labelTooltip="Department">
<fb:control>
<Input type="Text" id="department"/>
</fb:control>
</fb:FilterGroupItem>
</fb:filterGroupItems>
</fb:FilterBar>
<Table id="idF4" inset="true"
backgroundDesign="Translucent"
visibleRowCount="5"
noDataText="No data exists" >
<headerToolbar>
<Toolbar>
<Label text="User(s)"></Label>
</Toolbar>
</headerToolbar>
<columns>
<Column>
<Text text="User" type="Navigation"/>
</Column>
<Column minScreenWidth="small" popinDisplay="Inline" demandPopin="true">
<Text text="First Name" type="Navigation" />
</Column>
<Column minScreenWidth="small" popinDisplay="Inline" demandPopin="true">
<Text text="Last Name" type="Navigation" />
</Column>
<Column>
<Text text="Department" type="Navigation"/>
</Column>
</columns>
<items>
<ColumnListItem type="Navigation" selected="true" press="handleLineItemPress">
<cells>
<Text />
<Text />
<Text />
<Text "/>
</cells>
</ColumnListItem>
</items>
</Table>
</content>
<beginButton>
<Button text="Cancel" press="onCloseDialog" />
</beginButton>
</Dialog>
</core:FragmentDefinition>
我没有动态绑定数据。而是遵循以下方法。
for (var i = 0; i < oData.results.length; i++) {
oEntry.Bname = oData.results[i].Bname;
oEntry.Name1 = oData.results[i].Name1;
oEntry.Name2 = oData.results[i].Name2;
oEntry.Department = oData.results[i].Department;
var oTemplate = new sap.m.ColumnListItem(
{
cells : [
new sap.m.Text({
text : oEntry.Bname
}),
new sap.m.Text({
text : oEntry.Name1
}),
new sap.m.Text({
text : oEntry.Name2
}),
new sap.m.Text({
text : oEntry.Department
}) ] } );
oTable.addItem(oTemplate);
}
现在,当我 select 来自此 table 的条目时,不会触发事件 "press"。
我也有一个控制器代码。
handleLineItemPress : function(oEvent){
var currentRowContext = oEvent.getParameter("rowContext");
},
真的吗?....
先好好看看你的代码。
您定义了一个 table -- 没有数据绑定 -- 所以它只有一个 ColumnListItem
并分配了一个 press
事件。
在您的代码中,您要向 table 添加更多 ColumnListItem
,而这些没有分配 press
事件。
现在您要问为什么这些行的 press
事件不起作用? ;-)
(附带说明一下,您不使用数据绑定的原因是什么?)