2013-06-10 3 views
0

я в настоящее время разбора JSON и отображения данных в элементе управления таблицы с помощью sapui5, но я не смог разобрать внутренние объекты значенияКак разобрать 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> 

Как я выборки внутренних значений элементов, таких как имя пользователя и идентификатор и т.д ..

ответ

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

+0

спасибо, он работает сейчас !!! – vin

1
var arr = oModel.getData(); 

С помощью этого вы получите данные для этой модели, то вы можете перебрать данных или разобрать его.

+0

Не могли бы вы также рассказать, как мы можем применять фильтры к модели JSon. Есть идеи? –

+0

Вы можете пройти через этот документ, который даст краткое описание. JSONModel - это набор ваших данных, вы можете отфильтровать его или вы можете устанавливать фильтры, когда вы привязываете данные, это полностью зависит от требований. Https: //openui5.hana.ondemand.com/#docs/api/symbols/sap.ui .model.Filter.html –