gpt4 book ai didi

javascript - Xively 使用 javascript 从 feed 获取数据流列表

转载 作者:行者123 更新时间:2023-11-28 20:17:24 24 4
gpt4 key购买 nike

我正在尝试获取单个提要中所有数据流的列表并显示其当前值。我正在使用此处的文档和教程:http://xively.github.io/xively-js/docs/ 。我尝试在下面编写一个简单的 JavaScript 代码,但它不起作用。

<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="http://d23cj0cdvyoxg0.cloudfront.net/xivelyjs-1.0.4.min.js"></script>
</head>
<body>
<h1>Xively Test</h1>
<h2>
<small>Datastream list</small>
</h2>
</p>
<script>
xively.setKey("yWYxyi3HpdqFCBtKHueTvOGoGROSAKxGRFAyQWk5d3JNdz0g");
xively.datastream.list(
61916 //id from the tutorial example
, function (data) {
data.results.forEach(function (datastream) {
document.write("<br><br>Datastream ID:"+JSON.stringify(datastream["id"]
document.write("<br><br>Current value:"+JSON.stringify(datastream["current_value"], null, 4));
});
});
</script>
</body>
</html>

知道为什么它不起作用吗?

谢谢

最佳答案

您的 JavaScript 中有一些错误

  1. 您的数据参数中没有结果对象。
  2. document.write 语句中存在语法错误

试试这个代码:

<script>
xively.setKey("yWYxyi3HpdqFCBtKHueTvOGoGROSAKxGRFAyQWk5d3JNdz0g");
xively.datastream.list(
61916 //id from the tutorial example
, function (data) {
data.forEach(function (datastream) {
document.write("<br><br>Datastream ID:"+JSON.stringify(datastream["id"]));
document.write("<br><br>Current value:"+JSON.stringify(datastream["current_value"], null, 4));
});
});
</script>

关于javascript - Xively 使用 javascript 从 feed 获取数据流列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18958581/

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