雅虎财务流星套餐,股票代码的困难

时间:2015-05-05 00:11:42

标签: meteor yahoo-finance

我成功连接了Meteor Yahoo财务套餐。当我使用像这个“GOOG”这样的股票代码时,它工作正常,但是当我使用类似“ENW.V”的东西时,它会失败。

这是我的库存模板

<template name="stock">
  <h2>{{stock.symbol}}</h2>
    <ul>
    <li><strong>Name</strong> {{stock.name}}</li>
    <li><strong>Ask</strong> {{stock.ask}}</li>
    <li><strong>Bid</strong> {{stock.bid}}</li>
  </ul>
</template>

这是我的客户端代码。

Template.stock.rendered = function (){

  if ( _.isEmpty(Session.get('ENW.V')) ) {
    Meteor.call('getQuote', 'ENW.V', function(err, result) {
                Session.set('ENW.V', result.ENW.V); // I think this is the error          });
    }
}

Template.stock.helpers({
    stock: function() {
        return Session.get('ENW.V');
    }
})

这是我的服务器端代码

Meteor.methods({
  getQuote: function( stockname ) {
    return YahooFinance.snapshot({symbols: [stockname] });
  }
});

我的假设是结果.ENW.V导致错误,我猜测结果来自getQuote方法并且必须有一种方法来获取result.ENW.V而不必拥有“ .V“部分。

如果需要,我非常乐意添加更多信息。这是我在YQL控制台搜索中查看的股票。 https://goo.gl/hJvkSs

添加了括号表示法的新错误

  

提供调用'getQuote'的结果时出现异常:ReferenceError:   ENW未定义

1 个答案:

答案 0 :(得分:0)

使用bracket notation访问无效标识符的属性:

result['ENW.V']
相关问题