sapui5 - Sorting a list in SAPUI5
问题描述
I have a doubt regarding SAPUI5 Sort method.
var sOrder = "asc"
oView.byId("myList").getBinding("items").sort(
sOrder && new Sorter("LastName", sOrder === "desc")
);
In the above code, I have following doubts.
what exactly is sort method accepting?
what does the && mean to in this context and how it's affecting the sorting?
this is the project Project link
Please share your views
解决方案
1. this is the model that is used in the application: sap.ui.model.odata.v4.ODataListBinding. the method sort() of sap.ui.model.odata.v4.ODataListBinding
accepts as optional argument one of those:
sap.ui.model.Sorter
sap.ui.model.Sorter[]
2. &&
in this context means that if the first expression is convertable to true
then return the second expression. therefore, if sOrder
of sOrder && new Sorter("LastName", sOrder === "desc")
is true then return new Sorter("LastName", sOrder === "desc")
. but if the first expression is convertable to false
then return the first expression.
this affects the sorting in so far that the sap.ui.model.Sorter
of the second expression new Sorter("LastName", sOrder === "desc")
gets only returned if sOrder
is converted to true
. it does not have a falsy value. hence, the sort()
method of sap.ui.model.odata.v4.ODataListBinding
gets only called and therefore the sap.m.table
sorted if the first expression is not a falsy. falsy values are:
false
null
undefined
0
NaN
''
""
document.all
in the stated application you find aStates = [undefined, "asc", "desc"]
and var sOrder = aStates[iOrder]
. this means, sOrder
gets undefined
, "acs"
or "desc"
assigned. this means again, that in the context of sOrder && new Sorter("LastName", sOrder === "desc")
the sap.m.Table
gets sorted if "acs"
or "desc"
is assigned to sOrder
.
推荐阅读
- python - Python:预处理数据以挖掘关联规则和频繁项集(apriori/SPADE)
- linux - 与 ifconfig 命令相比,ip addr 命令在为接口分配 IP 时设置了不正确的子网掩码
- c# - 新手和数据 SQL 数据库
- vim - vim 以不同于 `hlsearch` 的方式突出显示当前出现的搜索模式,以帮助快速找到光标位置
- excel - 将 Excel Windows 大小更改为屏幕的一半
- python - 如何从父实例创建子 SQL-Alchemy 实例?
- c# - MoreLinq - 如何在不从选择器中获取空值的情况下进行 FullJoin?
- java - Spring Gateway RouteLocator 空指针异常
- php - 我收到“PHP 致命错误:无法重新声明函数”,尽管我只有一次该函数
- typescript - 如何在角度 8 中减少 viewchild 的线?