gpt4 book ai didi

javascript - 带 Meteor 的动态 SVG

转载 作者:行者123 更新时间:2023-12-03 11:16:08 25 4
gpt4 key购买 nike

我有一个 SVG 温度计,可以将动态数据拉入其中。我在显示 mongo 文档中的数据时没有问题,但是我真的很想弄清楚如何从返回的数据中获取值并将其应用于公式以设置 SVG 元素 (tempBarXPosition) 的 X 位置。

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>

最佳答案

据我所知,您的 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];

关于javascript - 带 Meteor 的动态 SVG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27343938/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com