UI5 - 具有XML模型渲染问题的TreeTable

时间:2017-02-18 00:44:33

标签: javascript xml treeview sapui5

我目前正在使用XML数据模型在XML视图中构建树表。

以下是我的XML:

<?xml version="1.0" encoding="utf-8"?>
<Rowsets>
    <Rowset>
        <Row>
            <root>
                <id>root</id>
                <level>root</level>
                <children>
                    <id>01</id>
                    <level>01</level>
                    <name>Case Packer</name>
                    <children>
                        <id>0101</id>
                        <level>0101</level>
                        <name>Unscheduled</name>
                    </children>
                    <children>
                        <id>0102</id>
                        <level>0102</level>
                        <name>Lunch</name>
                    </children>
                    <children>
                        <id>0103</id>
                        <level>0103</level>
                        <name>Scheduled Operations</name>
                        <children>
                            <id>010301</id>
                            <level>010301</level>
                            <name>Cleaning</name>
                        </children>
                        <children>
                            <id>010302</id>
                            <level>010302</level>
                            <name>Major Changeover</name>
                        </children>
                        <children>
                            <id>010303</id>
                            <level>010303</level>
                            <name>Paid Break</name>
                        </children>
                        <children>
                            <id>010304</id>
                            <level>010304</level>
                            <name>Running Production</name>
                            <children>
                                <id>01030401</id>
                                <level>01030401</level>
                                <name>Lowrater</name>
                            </children>
                            <children>
                                <id>01030402</id>
                                <level>01030402</level>
                                <name>Labeler 1</name>
                            </children>
                            <children>
                                <id>01030403</id>
                                <level>01030403</level>
                                <name>Depalletizer</name>
                            </children>
                            <children>
                                <id>01030404</id>
                                <level>01030404</level>
                                <name>Filler</name>
                            </children>
                            <children>
                                <id>01030405</id>
                                <level>01030405</level>
                                <name>Bottle Coder</name>
                            </children>
                        </children>
                    </children>
                </children>
            </root>
        </Row>
    </Rowset>
</Rowsets>

以下是我的XML视图:

<?xml version="1.0" encoding="utf-8" ?>
<core:View 
    xmlns:core="sap.ui.core" 
    xmlns:mvc="sap.ui.core.mvc"
    xmlns:l="sap.ui.layout"
    xmlns="sap.m" 
    xmlns:t="sap.ui.table" 
    controllerName="treetabledemo.TreeTableDemo"
    xmlns:commons="sap.ui.commons" 
    xmlns:common="sap.suite.ui.commons"
    xmlns:h="http://www.w3.org/1999/xhtml">
    <Page showHeader="false" enableScrolling="false" class="donuts">
        <l:Splitter orientation="Vertical">
            <l:contentAreas>
                <Page title="TreeTableDemo">
                    <content>
                    <t:TreeTable id="idProductionTable" rows="{path:'/Rowsets/Rowset/Row/root', parameters: {arrayNames:['/children']}}">

                            <t:toolbar>
                                <Toolbar>
                                    <Title text="Production"/>
                                </Toolbar>
                            </t:toolbar>
                            <t:columns>
                                <t:Column width="130px" demandPopin="true" id="idProdReportNode" showSortMenuEntry="false"
                                                         minScreenWidth="Tablet">
                                    <Label text="NAME" design="Bold" class="TableLabelColor" />
                                    <t:template>
                                        <ObjectIdentifier text="{name}" />
                                    </t:template>
                                </t:Column>
                                <t:Column width="130px" demandPopin="true" id="idProdReportProdCount" showSortMenuEntry="false"
                                                        minScreenWidth="Tablet" hAlign="End">
                                    <Label text="Level" design="Bold" class="TableLabelColor" />
                                    <t:template>
                                        <ObjectIdentifier text="{level}" />
                                    </t:template>
                                </t:Column>
                            </t:columns>
                        </t:TreeTable>
                    </content>
                </Page>
            </l:contentAreas>
        </l:Splitter>
    </Page>
</core:View>

以下是我的控制员:

sap.ui.controller("treetabledemo.TreeTableDemo", {

onInit: function() {

    var sPath = "resources/data/treedata.xml"; 
    var oModel = new sap.ui.model.xml.XMLModel(sPath);
    var that = this;

    var oTable = this.byId("idProductionTable");
    oTable.setModel(oModel);    

    },

});

但它给了我以下错误:

Uncaught Error: Path path:'/Rowsets/Rowset/Row/root', parameters: {arrayNames:['/children']} must start with a / 
    at d.a.getContext (sap-ui-core.js:1549)
    at f.c.applyFilter (sap-ui-core.js:1381)
    at f.c.checkUpdate (sap-ui-core.js:1386)
    at f.B.initialize (sap-ui-core.js:1313)
    at f.h._bindAggregation (sap-ui-core.js:511)
    at f.z._bindAggregation (Table.js:6)
    at f.h.updateBindings (sap-ui-core.js:517)
    at f.h.setModel (sap-ui-core.js:528)
    at constructor.onInit (TreeTableDemo.controller.js:15)
    at f.a.fireEvent (sap-ui-core.js:449)

我尝试了各种排列和组合,但它似乎不起作用。

我在这里做错了什么?

1 个答案:

答案 0 :(得分:1)

对于XML模型,根目录不得包含在路径中。您应该从文档here中删除绑定路径中的 / Rowsets

所以路径应该是

  <?php
  session_start();
   include("connection.php");
   extract($_REQUEST);
   extract($_POST);

  if(isset($submit)==true)
   {
  $query=mysql_query("update account SET password='$password' where passcode='$restkey'") or die(mysql_error());
  echo"Password Updated Successfully";
  }



  if(isset($restkey)==true)
  {

  echo"<form action='' method='post'>
  <table>
  <tr><td>Password</td><td><input type='password' required name='password' /></td></tr>
 <tr><td></td><td><input type='submit' name='submit' value='submit' /></td></tr>
 </form>";
 }
 ?>

但是你现在有第二个问题,因为你的TreeTable看起来像这样。 enter image description here

这是因为与JSON模型相比,XML模型的工作方式不同,这使得绑定路径语法有些困难。

rows="{path:'/Rowset/Row/root', parameters: {arrayNames:['/children']}}"

在上面,模型将考虑根子节点有4个子节点。为了解决这个问题,id,level&amp; name应该是children对象的属性。

所以你的treedata.xml应该是这样的。

<children>
                <id>01</id>
                <level>01</level>
                <name>Case Packer</name>
                <children>
                    <id>0101</id>
                    <level>0101</level>
                    <name>Unscheduled</name>
                </children>
</children>

使用此功能,您可以将属性绑定为{@id},{@ level},{@ name}

<?xml version="1.0" encoding="utf-8"?>
<Rowsets>
    <Rowset>
        <Row>
            <root id="root" level="root">
                <children id="01" level="01" name="Case Packer">
                    <children id="0101" level="0101" name="Unscheduled" />
                    <children id="0102" level="0102" name="Lunch" />
                    <children id="0103" level="0103" name="Scheduled Operations">
                        <children id="010301" level="010301" name="Cleaning" />                                                                               
                        <children id="010302" level="010302" name="Major Changeover" />                                                                               
                        <children id="010303" level="010303" name="Paid Break" />                                                                               
                        <children id="010304" level="010304" name="Running Production">                                                                               
                            <children id="01030401" level="01030401" name="Lowrater" />                                                                                
                            <children id="01030402" level="01030402" name="Labeler 1" />                                                                                
                            <children id="01030403" level="01030403" name="Depalletizer" />                                                                                
                            <children id="01030404" level="01030404" name="Filler" />                                                                                
                            <children id="01030405" level="01030405" name="Bottle Coder" />                                                                                
                        </children>
                    </children>
                </children>
            </root>
        </Row>
    </Rowset>
</Rowsets>