2016-01-27 116 views
1

目前我正在開發一個應用程序使用離子框架。如何從Ionic的外部JSON獲取數據?

我需要使用令牌和(保費或2基本1)參數

的URL顯示數據正確地從外部JSON文件中的數據,但我不明白如何從我的「消息頁控件獲取數據」。

我試試這個http://fdietz.github.io/recipes-with-angular-js/consuming-external-services/requesting-json-data-with-ajax.html

但在應用程序只能看到3塊沒有數據

我使用controller.js

// Controller of docs. 
appControllers.controller('docsCtrl', function ($scope, $mdBottomSheet, $mdToast, $mdDialog, $http) { 

    $http.get('https://www.domain.com/api/document?__token=[the_token_added_on_code]&__idPortal=1'). 
    success(function(data, status, headers, config) { 
     $scope.docs = data; 
    }). 
    error(function(data, status, headers, config) { 
    // log error 
    }); 

}); // End of docs controller. 

在HTML驗證碼:

<ion-view view-title="Documentos"> 

    <!--dashboard section--> 
    <ion-content id="docs-content"> 

     <div class="documentos padding"> 

      <ion-list> 
       <ion-item ng-repeat="doc in docs" class="item-avatar"> 
        <h2>{{doc.name}}</h2> 
        <p>{{doc.description}}</p> 
        <p>{{doc.created}}</p> 
       </ion-item> 
      </ion-list> 
     </div> 

    </ion-content><!--end dashboard section--> 
</ion-view> 

最後,URL返回此數據:

{"success":true,"return":{"totalItem":"33","totalPages":7,"pageSize":5,"itens":[{"id_document":"4760","name":"Teste","created":"02\/09\/2015 16:57:00","id_type":"108","type":"Documento Teste","description":"Documento"},{"id_document":"4722","name":"Ata de assembleia 08\/2015","created":"31\/08\/2015 17:32:55","id_type":"3","type":"Ata da assembl\u00e9ia","description":null},{"id_document":"4400","name":"Regimento","created":"04\/08\/2015 16:47:30","id_type":"108","type":"Documento Teste","description":"Regimento interno "},{"id_document":"4261","name":"ATA da AGE em 18\/09","created":"26\/07\/2015 22:22:39","id_type":"3","type":"Ata da assembl\u00e9ia","description":null},{"id_document":"2964","name":"Novo regimento playground","created":"05\/05\/2015 14:30:17","id_type":"91","type":"Regimento Interno","description":"Segue novo regimento playground"}]}} 

在前進,感謝對您的支持

回答

2

如果你返回正確的數據,你必須從ATTR itens

$scope.docs = data.itens; 

拿到物品後,請登錄您的數據console.log(data)找到屬性物體並導航到它 {status: true, return: { .. itens:[] }}

$scope.docs = data.return.itens 
+0

Wh我看到這個日誌? – Carlos

+0

工作:$ scope.docs = data.return.itens; – Carlos

+0

要在Windows中使用谷歌瀏覽器查看日誌,請按F12或菜單>更多工具>開發者工具 –