【问题标题】:Yahoo Finance Meteor Package, difficulty with stock symbol雅虎财经流星包,股票代码困难
【发布时间】:2015-05-05 08:25:55
【问题描述】:

我已成功连接了 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] });
  }
});

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

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

添加了括号符号的新错误

传递调用“getQuote”的结果时出现异常:ReferenceError: ENW 未定义

【问题讨论】:

    标签: meteor yahoo-finance


    【解决方案1】:

    使用bracket notation 访问不是有效标识符的属性:

    result['ENW.V']
    

    【讨论】:

    • 我现在非常接近,我现在收到此错误Exception in delivering result of invoking 'getQuote': ReferenceError: ENW is not defined
    • 我缺少单引号 'ENW.V' 谢谢
    • 是的,所有细节都很重要:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-06
    • 1970-01-01
    • 2015-06-11
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    相关资源
    最近更新 更多