2017-07-16 50 views
0

我想顯示的CSV數據,我得到顯示單個數據,而不是多個數據,以顯示輸出如下:的Javascript:從行

Price: 955.99 
EPS: 29.59 
Date : 7/14/2017 

但是,我得到的輸出如下:

enter image description here

連續示出,但是單獨用col0col2col4

  • 價格是col0
  • 每股收益col2
  • 日期是col4

yahooStock.js

angular.module('app').factory('yahooStock',function($http){ 
    //yahoo query api 
    var yqlUrl = "https://query.yahooapis.com/v1/public/yql"; 
    //historical api queryied by yql.. 
    var historicalUrl = 'https://finance.yahoo.com/d/quotes.csv'; 
    //template to put query params into 
    var queryTemplate = _.template("select * from csv where url='" + historicalUrl + "?s=<%= symbol %>&f=<%= code %>'"); 

    function _request(symbol,code){ 
    return $http({ 
     method:"GET", 
     url: yqlUrl, 
     params: {q: queryTemplate({symbol:symbol,code:code}), format: 'json'} 
    }).then(function(response){ 
     console.log('response',response.data); 
     return {data:response.data.query.results.row}; 
    }); 

    } 

    var factory = { 
    getYahooData: function(symbol){ 
     return _request(symbol, 'l1,e,d1');}, 
}; 

    return factory; 

}); 

main.js

angular.module("app",['ionic']).controller("mainCtrl",function($scope,yahooStock){ 
    yahooStock.getYahooData('GOOG').then(function(response){ 
    $scope.data = response.data; 
    }); 
}); 

的.html

<ion-content has-header="true"> 
     <p>Price: {{data}}</p> 
     <p>EPS: {{data}}</p> 
     <p>Date: {{data}}</p> 
     <!-- our list and list items --> 
     <ion-list> 
      <ion-item ng-repeat="stock in stocks"> 
      {{stock.title}} 
      </ion-item> 
     </ion-list> 
     </ion-content> 

我已附上plunker鏈接。

https://plnkr.co/edit/4bxI8Qd8ftVfaE4D7veN?p=preview

回答

3
<p>Price: {{data.col0}}</p> //col0 is price 
<p>EPS: {{data.col2}}</p> // col2 is EPS 
<p>Date: {{data.col4}}</p> //col44 is Date 

// COL1和COL3爲空,如果他們不相關刪除它們。

+0

如何刪除col1和col3? – lotteryman