Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
705 views
in Technique[技术] by (71.8m points)

sapui5 - Aggregation binding only shows last item

Hello I am trying to bind an aggregation onto a Table control but the resulting rows are repeated with the last result in the data set. To elaborate, the table contains the correct amount of rows and columns, but each row repeats the same data.

Doing a OData read call and putting the results into a JSON model and binding that model onto the table works, but that seems unnecessarily expensive.

The binding portion

var filter = new Filter("itemID", sap.ui.model.FilterOperator.EQ, this.item.itemID);  
this._template = this._template ? this._template : sap.ui.xmlfragment("InventoryListItem", this.getView().getController());
this.inventoryList.bindAggregation("items", {
    path: "oDataModel>/InventoryUsages",
    filters: [filter],
    template: this._template,
    parameters: {
      select: 'inventoryID,memberID,fName,lName,condition,purchasedAt,price'
   }
});

The template:

<core:FragmentDefinition
xmlns="sap.m"
xmlns:core="sap.ui.core"
xmlns:l="sap.ui.layout">
<ColumnListItem>
    <cells>
        <Text text="{path: 'oDataModel>inventoryID'}" />
        <Text text="{parts:[{path:'oDataModel>fName'}, {path:'oDataModel>lName'}], formatter:'.nameFormater'} " />
        <Text text="{oDataModel>purchasedAt}" />
        <RatingIndicator maxValue="5" class="sapUiSmallMarginBottom" value="{
            path: 'oDataModel>condition', formatter: '.conditionFormat'}"
            change="onRatingPress"/>
        <Text text="{path:'oDataModel>price', formatter: '.priceFormatter'}" />
        <Button text="Remove"
            icon="sap-icon://delete"
            press="onRowDelete"
            class="appBtn"/>
    </cells>
</ColumnListItem>

The table displays the correct number of rows, and columns but the data is wrong. It will display the last result in the set for each row. When the table grows the table will show the next last result in the set. Does anyone know how i can fix this?


Answer: Turns out i was doing an OData call on a view that didn't have a primary key. The render glitches out and only displays the last result for some reason as a result.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Well I figured out the answer to my own question it turns out because I am doing an OData call to a view that does not have a primary key. If it doesn't have a primary key it will glitch out and display the last result of the data set. (If you are using a ASP.net web api you can just put the [key] annotation in the model to solve this problem).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...