SAPUI5 - 不按升序或降序对列表项进行分组 [英] SAPUI5 - Group list items without sorting ascending or descending
问题描述
我在我的应用程序中使用了一个 sap.m.List
控件,它应该显示一个顺序列表.每个列表数据中都有一个分组属性,我可以使用它来将相似的项目分组在一起.
I am using a sap.m.List
control in my application that is supposed to show a sequential list. There is a grouping property in each list data that I can use to group similar items together.
我检查了这个例子 在 SAP Explored 网站上关于列表分组.它使用 sorter
属性,该属性将 group
设置为 true
.默认情况下,排序模式为降序.
I checked this example on the SAP Explored website on list grouping. It uses a sorter
property that has group
set to true
. By default the sorting mode is descending.
但是,我的列表必须按预定义的顺序显示项目,为了便于使用,将相似的项目组合在一起.一组中的所有项目都出现在列表中的一个位置,而一个特定的组只出现一次.例如,我必须将下面的 JSON 数组按照与它相同的顺序绑定到一个列表中,仅按 Category
分组.
However my list has to show the items in a predefined sequence with just similar items grouped together for ease of use. All items in a group occur at one place in the list and a particular group occurs only once. For example, I have to bind the JSON array below to a list in the same order as it is, only grouped by Category
.
steps.json:
{
"Steps": [
{
"Desc": "Open google search",
"Category": "Google"
},
{
"Desc": "Search for Apple Inc.",
"Category": "Google"
},
{
"Desc": "Open Apple website",
"Category": "Apple"
},
{
"Desc": "Search for iPhone",
"Category": "Apple"
},
{
"Desc": "Browse all iPhone models",
"Category": "Phone"
},
{
"Desc": "Choose the one you like",
"Category": "Phone"
}
]
}
下面的代码是我想要做的,除了它按降序对我的列表进行排序.
The code below is what I would like to do in order to get going except it sorts my list in descending order.
SAPUI5 代码:
<List
items="{
path: '/Steps',
sorter: {
path: 'Category',
group: true
}
}"
headerText="Here's what you do">
<StandardListItem title="{Desc}" />
</List>
有没有办法做到这一点?
Is there a way to achieve this?
谢谢.
推荐答案
Sorter 的第三个参数可以是获取上下文作为参数的函数.
3rd parameter of the Sorter can be a function which gets the context as a parameter.
API:https://openui5.hana.ondemand.com/#docs/api/symbols/sap.ui.model.Sorter.html
示例:http://jsbin.com/votesatezu/1/edit?html,js,输出
这篇关于SAPUI5 - 不按升序或降序对列表项进行分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!