这基本上是针对这个问题的变通方法试验:" 如何在XML视图中使用自定义排序器 "
由于目前无法在XML视图中使用自定义排序器,我想也许可以在控制器中设置排序器.
你如何用JS视图做到这一点是这样的:
var oTemplate = ... // irrelevant
var oList = new sap.m.List({
id: this.createId("someList"),
items: {
path: "/list",
template: oTemplate,
sorter: foo.bar.CustomSorter
}
});
Run Code Online (Sandbox Code Playgroud)
当我想将其转换为XML视图时,我有以下内容:
<m:List id="someList"
items="{path: '/list'}">
<!-- hid ListItem implementation -->
</m:List>
Run Code Online (Sandbox Code Playgroud)
那么,如何在控制器中将分拣机设置到此列表中?还有,在哪里挂钩呢?选项:
onInitonBeforeRenderingonAfterRendering所以,我的期望是这样的:
sap.ui.controller("foo.bar.controller.SomeController", {
onInit : function(){
var oList = this.getView().byId("someList");
oList.get___Something___().setSorter(foo.bar.CustomSorter);
};
};
Run Code Online (Sandbox Code Playgroud)
但似乎不可能.
您可以使用列表绑定的sorter属性:
<List
id="invoiceList"
class="sapUiResponsiveMargin"
width="auto"
items="{
path : '/Invoices',
sorter : {
path : 'ProductName'
}
}" >
Run Code Online (Sandbox Code Playgroud)
https://sapui5.hana.ondemand.com/#docs/guide/c4b2a32bb72f483faa173e890e48d812.html
我也尝试用onInit设置分拣机,不幸的是this.getView().byId("whateverID")此时失败了......