XML 视图中的 SAPUI5 绑定筛选器



我想通过在XML视图绑定中使用过滤器来过滤sap.m.Table的条目,如下所示:

<Table id="__tableDetails" headerText="" mode="None" class="sapUiMediumMarginBottom" 
items="{ path: 'mymodel>/data', filters : [{ path : 'status', operator : 'EQ', value1 : 'ACTIVE' }]}">
<columns>
    <Column>
        <Label text="ID"/>
    </Column>
    <Column>
        <Label text="Description"/>
    </Column>
    <Column>
        <Label text="Language"/>
    </Column>
</columns>
<items>
    <ColumnListItem vAlign="Middle">
        <cells>
            <Text text="{mymodel>id}" wrapping="true"/>
            <Text text="{mymodel>desc}" wrapping="true"/>
            <Text text="{mymodel>lang}" wrapping="true"/>
        </cells>
    </ColumnListItem>
</items>
</Table>

当我删除过滤器时,绑定有效,但使用过滤器时,表中不会显示任何数据,尽管模型确实包含属性"status"的值为"ACTIVE"的条目。将运算符更改为"包含"而不是"EQ"并不能解决问题。

有人能在这里发现错误吗?非常感谢您的任何建议!

检查模型属性,因为代码很好。

这里的例子运行良好

<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv='X-UA-Compatible' content='IE=edge'>
		<meta charset="utf-8">
		<title>MVC with XmlView</title>
		<!-- Load UI5, select "blue crystal" theme and the "sap.m" control library -->
		<script id='sap-ui-bootstrap'
			src='https://sapui5.hana.ondemand.com/resources/sap-ui-core.js'
			data-sap-ui-theme='sap_belize_plus'
			data-sap-ui-libs='sap.m'
			data-sap-ui-xx-bindingSyntax='complex'></script>
		<!-- DEFINE RE-USE COMPONENTS - NORMALLY DONE IN SEPARATE FILES -->
		<!-- define a new (simple) View type as an XmlView
		 - using data binding for the Button text
		 - binding a controller method to the Button's "press" event
		 - also mixing in some plain HTML
		 note: typically this would be a standalone file -->
		<script id="view1" type="sapui5/xmlview">
  		<mvc:View xmlns="sap.m" xmlns:mvc="sap.ui.core.mvc" controllerName="my.own.controller">
          <Table id="__tableDetails" headerText="Filtered" mode="None" class="sapUiMediumMarginBottom" 
          items="{ path: 'mymodel>/data', filters : [{ path : 'status', operator : 'EQ', value1 : 'ACTIVE' }]}">
          <columns>
              <Column>
                  <Label text="ID"/>
              </Column>
              <Column>
                  <Label text="Description"/>
              </Column>
              <Column>
                  <Label text="Language"/>
              </Column>
          </columns>
          <items>
              <ColumnListItem vAlign="Middle">
                  <cells>
                      <Text text="{mymodel>id}" wrapping="true"/>
                      <Text text="{mymodel>desc}" wrapping="true"/>
                      <Text text="{mymodel>lang}" wrapping="true"/>
                  </cells>
              </ColumnListItem>
          </items>
          </Table>
          <Table id="__tableDetailsWithoutFilter" headerText="Without Filter" mode="None" class="sapUiMediumMarginBottom" 
          items="{ path: 'mymodel>/data' }">
          <columns>
              <Column>
                  <Label text="ID"/>
              </Column>
              <Column>
                  <Label text="Description"/>
              </Column>
              <Column>
                  <Label text="Language"/>
              </Column>
          </columns>
          <items>
              <ColumnListItem vAlign="Middle">
                  <cells>
                      <Text text="{mymodel>id}" wrapping="true"/>
                      <Text text="{mymodel>desc}" wrapping="true"/>
                      <Text text="{mymodel>lang}" wrapping="true"/>
                  </cells>
              </ColumnListItem>
          </items>
          </Table>
  		</mvc:View> 
    </script>
    <script>
      // define a new (simple) Controller type
      sap.ui.controller("my.own.controller", {
        onInit: function(){
          var oModelData = {
            data: [
              {id: 001, desc: "Active obj 1", lang: "en", status: "ACTIVE"},
              {id: 002, desc: "This is inactive", lang: "en", status: "INACTIVE"},
              {id: 003, desc: "Active obj 2", lang: "en", status: "ACTIVE"}
            ]
          };
          var oModel = new sap.ui.model.json.JSONModel(oModelData)
          this.getView().setModel(oModel, "mymodel")
        },
      });
      // instantiate the View
      var myView = sap.ui.xmlview({viewContent:jQuery('#view1').html()}); // accessing the HTML inside the script tag above
      // put the View onto the screen
      myView.placeAt('content');
    </script>
  </head>
  <body id='content' class='sapUiBody'>
  </body>
</html>

最新更新