Javascript:显示单个数据而不是一行中的多个数据

时间:2017-07-16 15:07:32

标签: javascript angularjs ionic-framework

我想显示我得到的CSV数据,以显示输出如下:

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

但是,我得到如下输出:

enter image description here

它连续显示,与col0col2col4分开。

  • 价格为col0
  • EPS为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

1 个答案:

答案 0 :(得分: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为null,如果不相关则删除它们。