sap.m.List没有对事件做出反应

时间:2015-11-04 10:35:38

标签: sapui5

我有以下列表,但它没有对我正在使用的任何事件作出反应。 在onSelectionChange方法中,我有断点并正在更新标签,但由于某种原因没有达到这一点。 onSearch方法运行正常。 我正在使用sapui5

<mvc:View
height="100%"
controllerName="Tasks.CompletedTasks.view.CompletedTasks"
xmlns:l="sap.ui.layout"
xmlns:core="sap.ui.core"
xmlns:mvc="sap.ui.core.mvc"
xmlns="sap.m">

        <SearchField
                liveChange="onSearch"
                width="100%" />
     <Label  id="label" text="test">

     </Label>
      <List
            id="idList"
            items="{/results}"
            select="onSelectionChange"
             >

            <items>
                <StandardListItem
                    title="{TaskTitle}"
                    description="{InstanceID}"
                icon="sap-icon://task"
                    iconDensityAware="false"
                    iconInset="false"
                    />
            </items>
        </List>

代码:

jQuery.sap.require("jquery.sap.resources");
jQuery.sap.require("sap.ui.model.Filter");
jQuery.sap.require("sap.ui.model.FilterOperator");
jQuery.sap.require("Tasks.CompletedTasks.util.ModelBuilder");
sap.ui.controller("Tasks.CompletedTasks.view.CompletedTasks", {

/**
* Called when a controller is instantiated and its View controls (if available) are already created.
* Can be used to modify the View before it is displayed, to bind event handlers and do other one-time initialization.
* @memberOf cscompletedtasks.CompletedTasks
*/
    onInit: function() {
    //this.getView().bindElement("/results");
    },

    onSelectionChange : function (oEvt) {

        var oList = oEvt.getSource();
        var oLabel = this.getView().byId("label");

        oLabel.setText("event");

    },
    onSearch : function (oEvt) {

        // add filter for search
        var aFilters = [];
        var sQuery = oEvt.getSource().getValue();
        if (sQuery && sQuery.length > 0) {
            var filter = new sap.ui.model.Filter("TaskTitle", sap.ui.model.FilterOperator.Contains, sQuery);
            aFilters.push(filter);
        }

        // update list binding
        var list = this.getView().byId("idList");
        var binding = list.getBinding("items");
        binding.filter(aFilters, "Application");
    }



});

HTML

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv='Content-Type' content='text/html;charset=UTF-8' />

<script id="sap-ui-bootstrap"
    src="https://sapui5.netweaver.ondemand.com/resources/sap-ui-core.js"
    data-sap-ui-theme="sap_bluecrystal"
    data-sap-ui-libs="sap.m"
    data-sap-ui-xx-bindingSyntax="complex"
    data-sap-ui-resourceroots='{"Tasks.CompletedTasks" : "./" }'>

</script>

<script>
    new sap.ui.core.ComponentContainer( {
        name : "Tasks.CompletedTasks"
    }).placeAt("content");
</script>

</head>
<body class="sapUiBody" id="content">
</body>
</html>

2 个答案:

答案 0 :(得分:1)

如果您在列表上设置选项的模式,则选择事件会有效。

<List
            id="idList"
            items="{/results}"
            select="onSelectionChange",
            mode="" //Type of mode you required SingleSelect,MultiSelect, Delete default it is None.
             >

            <items>
                <StandardListItem
                    title="{TaskTitle}"
                    description="{InstanceID}"
                icon="sap-icon://task"
                    iconDensityAware="false"
                    iconInset="false"
                    />
            </items>
        </List>

请参阅此link以获取更多信息

答案 1 :(得分:0)

请将此插入处理onSelectionChange事件的函数顶​​部:

jQuery.sap.log.setLevel(jQuery.sap.log.LogLevel [&#39; INFO&#39;]); jQuery.sap.log.info(&#34; ***我的onSelectionChange已触发&#34;);

即:

onSelectionChange : function (oEvt) {

   jQuery.sap.log.setLevel(jQuery.sap.log.LogLevel['INFO']); 
   jQuery.sap.log.info("*** my onSelectionChange has triggered");
   var oList = oEvt.getSource();

然后检查浏览器的控制台并过滤以查找此消息的输出。 (以防万一事件正在触发,你的后续代码没有做任何事情。(如果你已经将LogLevel设置在别处,请忽略)