2014-12-07 86 views
0

我有一個SVG溫度計,我把動態數據導入。我從mongo文檔中顯示數據沒有問題,但我真的被困在試圖找出如何從返回的數據中取值並將其應用於公式以設置SVG元素(tempBarXPosition)的X位置。動態SVG與流星

if (Meteor.isClient) { 
// This code only runs on the client 
    pullTempData = Tasks.find({_id: "scQGmhzsCffJeGqt"}); 
    Template.body.helpers({ 
    resData: function() { 
     return pullTempData; 
    }, 
    tempBarXposition: function(){ 
    return pullTempData.temperature + 50; // <---- this doesn't work 
    } 
}); 

是否有可能引用助手函數自身內的pullTempData對象返回的{{temperature}}的值?

HTML文件(第一行不行?第二呢)

<line fill="none" stroke="#e5e5e5" stroke-width="4" stroke-dasharray="null" stroke-linejoin="null" stroke-linecap="null" x1="{{tempBarXPosition}}" y1="280" x2="{{tempBarXPosition}}" y2="250" id="temp_bar"/> 
<text fill="#00ff00" stroke="#000000" stroke-width="0" stroke-dasharray="null" stroke-linejoin="null" stroke-linecap="null" stroke-opacity="0" x="66.875" y="300.25" font-size="20" font-family="Sans-serif" text-anchor="middle" xml:space="preserve" id="temp_value">{{temperature}}</text> 

回答

1

從我所看到的,你pullTempData是一個光標。嘗試得到一個文件:

//Use findOne() to have a document 
pullTempData = Tasks.findOne({_id: "scQGmhzsCffJeGqt"}); 

或者如果你喜歡:

//Use find().fetch()[0] to get the first element of the cursor, if any! 
pullTempData = Tasks.find({_id: "scQGmhzsCffJeGqt"}).fetch()[0];