如何在 SAPUI5 中的 Controller 中设置 List 的排序器? [英] How to set sorter of a List in Controller in SAPUI5?
问题描述
这基本上是这里问题的解决方法试验:如何在 XML 视图中使用自定义排序器"
This is basically a workaround trial for the question here : "How to use custom sorter in XML views"
由于目前无法在 XML 视图中使用自定义排序器,我想也许可以在控制器中设置排序器.
Since currently it is not possible to use custom sorters in XML views, I thought maybe it is possible to set the sorter in the controller.
您如何使用 JS 视图执行此操作:
How you do that with JS view is like this:
var oTemplate = ... // irrelevant
var oList = new sap.m.List({
id: this.createId("someList"),
items: {
path: "/list",
template: oTemplate,
sorter: foo.bar.CustomSorter
}
});
当我想将其转换为 XML 视图时,我有以下内容:
And when I want to convert that to and XML view, I have the following:
<m:List id="someList"
items="{path: '/list'}">
<!-- hid ListItem implementation -->
</m:List>
那么,如何在控制器中为这个列表设置一个排序器?还有,在哪里挂?选项:
Then, how can I set a sorter to this list in controller? Also, where to hook it? Options:
onInit
onBeforeRendering
onAfterRendering
所以,我的预期是这样的:
So, what I expected was something like:
sap.ui.controller("foo.bar.controller.SomeController", {
onInit : function(){
var oList = this.getView().byId("someList");
oList.get___Something___().setSorter(foo.bar.CustomSorter);
};
};
但似乎不可能.
推荐答案
onInit 应该没问题.
onInit should be fine.
使用 List 的方法 bindItems绑定项目并应用排序器.
Use List's method bindItems to bind the items and apply the sorter.
类似于:
oList.bindItems('/list', ListItemTemplate, foo.bar.CustomSorter);
oList.bindItems('/list', ListItemTemplate, foo.bar.CustomSorter);
问候,金莫
这篇关于如何在 SAPUI5 中的 Controller 中设置 List 的排序器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!