0

我目前正在解析 json 并使用 sapui5 在表格控件中显示数据,但我无法解析内部对象值

代码:

<!DOCTYPE html>
<html><head>
    <meta http-equiv='X-UA-Compatible' content='IE=edge' />
    <title>Table example</title>

    <!-- Load UI5, select gold reflection theme and the "commons" and "table" control libraries -->
    <script id='sap-ui-bootstrap' type='text/javascript'
       src='resources/sap-ui-core.js'
       data-sap-ui-theme='sap_goldreflection'
       data-sap-ui-libs='sap.ui.commons,sap.ui.table'></script>

    <script>

        // create the DataTable control
        var oTable = new sap.ui.table.Table({editable:true});

        // define the Table columns
        var oControl = new sap.ui.commons.TextView({text:"{comments/data/from/username}"});     // short binding notation
        oTable.addColumn(new sap.ui.table.Column({label: new sap.ui.commons.Label({text: "Group"}), template: oControl }));

        var oControl = new sap.ui.commons.TextView({text:"{comments/data/from/id}"}); // short binding notation
        oTable.addColumn(new sap.ui.table.Column({label: new sap.ui.commons.Label({text: "Group Text"}), template: oControl }));

        var oModel = new sap.ui.model.json.JSONModel();

        var aData = 
       jQuery.ajax({

                url: "https://api.instagram.com/v1/media/popular?client_id=d6ff37e000de4fc7882e4e5fccfff236",  // for different servers cross-domain restrictions need to be handled

                dataType: "json",

                success: function(data, textStatus, jqXHR) { // callback called when data is received
                    var JsonData = data;
                   oModel.setData(JsonData);  // fill the received data into the JSONModel
                    alert("sparta");

                },

                error: function(jqXHR, textStatus, errorThrown) {
                      alert("error");
                }

            });
        // create a JSONModel, fill in the data and bind the Table to this model


      // oModel.setData(aData);
        oTable.setModel(oModel);
        oTable.bindRows("/data");

        // finally place the Table into the UI
        oTable.placeAt("content");

    </script>

    </head>
    <body class='sapUiBody'>
        <div id='content'></div>
    </body>
</html>

我如何获取内部元素值,例如用户名和 id 等。

4

2 回答 2

1

尝试类似的东西

var oControl = new sap.ui.commons.TextView().bindProperty("text", "user/usernme");
oTable.addColumn(new sap.ui.table.Column({label: new sap.ui.commons.Label({text: "User Name"}), template: oControl}));

var oControl = new sap.ui.commons.TextView().bindProperty("text", "user/id");
oTable.addColumn(new sap.ui.table.Column({label: new sap.ui.commons.Label({text: "UserID"}), template: oControl}));

https://sapui5.hana.ondemand.com/sdk/#docs/guide/JSONModel.html

于 2013-06-10T12:10:00.240 回答
1
var arr = oModel.getData();

使用它您可以获得该模型的数据,然后您可以遍历数据或解析它。

于 2013-07-31T06:51:16.347 回答