绑定实体以获取单个记录



如何获取单个实体记录数据请找到下面的代码 在 XML 中绑定 table.am 如下所示

table in xml view 
<Table  items="{/dum}" id="table" width="auto">

当可以将 url 直接绑定到表时:

如果我像下面这样给出,我会得到所有记录。

 var url = "/myentity";
    var table = oView.byId("table");
    table.bindItems({
        path: url,
        template: table.getBindingInfo("items").template
    });

如果我给var url = "/myentity('srujan')";无法获取特定用户数据

HTTP request failed400,Bad Request,{"error":{"code":"005056A509B11EE1B9A8FEC11C23378E","message":{"lang":"en","value":"System query options '$orderby,$skip,$top,$skiptoken,$inlinecount' are not allowed in the requested URI"

下面是一个片段,显示了 bindElement(XML 中的"绑定")如何适用于您的情况:

var oModel = new sap.ui.model.json.JSONModel({
    "Product(1)": {
      Price: 100,
      Name: "Product # 1"
    },
    Products: [{
      Price: 200,
      Name: "Product # 1"
    }, {
      Price: 500,
      Name: "Product # 2"
    }, {
      Price: 542,
      Name: "Product # 3"
    }]
  });
  sap.ui.getCore().setModel(oModel);
  sap.ui.xmlfragment({
    fragmentContent: document.getElementById("table").textContent
  }).placeAt("content");
<!DOCTYPE html>
<html>
<body>
  <script src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js" id="sap-ui-bootstrap" data-sap-ui-theme="sap_bluecrystal" data-sap-ui-libs="sap.m"></script>
  <script id="table" type="sapui5/xml">
    <Table xmlns="sap.m" binding="{/Product(1)}">
      <columns>
        <Column>
          <Label text="Binding" />
        </Column>
        <Column>
          <Label text="Column 2" />
        </Column>
        <Column>
          <Label text="Column 3" />
        </Column>
      </columns>
      <items>
        <ColumnListItem>
          <Text text="/Products(1) on table" />
          <Text text="{Name}" />
          <Text text="{Price}" />
        </ColumnListItem>
        <ColumnListItem binding="{/Products/2}">
          <Text text="/Products/2 on item" />
          <Text text="{Name}" />
          <Text text="{Price}" />
        </ColumnListItem>
      </items>
    </Table>
  </script>
  <div id="content"></div>
</body>
</html>

最新更新