2015-05-05 112 views
1

我已經成功搭建了流星雅虎財務套餐。當我使用像這樣的「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方法來,因此必須成爲獲取結果的一種方法.ENW.V不必具有「.V」部分。

如果需要,我很樂意添加更多信息。這裏是我在YQL控制檯搜索中查看的股票。 https://goo.gl/hJvkSs

用括號標記新的錯誤添加

Exception in delivering result of invoking 'getQuote': ReferenceError: ENW is not defined

回答

0

使用bracket notation訪問哪些是無效的標識符屬性:

result['ENW.V'] 
+0

我很接近現在,我得到這個錯誤現在'異常發送調用'getQuote'的結果:ReferenceError:ENW未定義' – Kitch

+0

我錯過了單引號'''ENW.V''謝謝 – Kitch

+0

是的,所有的細節問題':)' –