Javascript 为什么thingspeak中的所有字段或提要都返回所有字段或提要,而不是一个或两个?
我有读取thing speak频道数据的代码,我的问题是,当我将数据作为一个字段读取时。但文件格式的数据似乎将所有提要都读取为数据。对我来说这是一个问题,但对用户来说没有任何意义。问题是有什么方法可以改进,或者thing speak可以更好地增强文档的可读性?这是我的代码,前端和Jquery在下载日期范围时读取数据,并带有复选框。如果用户必须选择该字段,并且期望只能在文件格式上看到该字段的温度或照度,则复选框用于该字段的选项Javascript 为什么thingspeak中的所有字段或提要都返回所有字段或提要,而不是一个或两个?,javascript,jquery,ajax,Javascript,Jquery,Ajax,我有读取thing speak频道数据的代码,我的问题是,当我将数据作为一个字段读取时。但文件格式的数据似乎将所有提要都读取为数据。对我来说这是一个问题,但对用户来说没有任何意义。问题是有什么方法可以改进,或者thing speak可以更好地增强文档的可读性?这是我的代码,前端和Jquery在下载日期范围时读取数据,并带有复选框。如果用户必须选择该字段,并且期望只能在文件格式上看到该字段的温度或照度,则复选框用于该字段的选项 div class = "custom-control custom-
div class = "custom-control custom-checkbox">
<input type="checkbox" class ="custom-control-input" id="temperature">
<label class = "custom-control-label" for="temperature">Temperature</label>
</div>
<div class = "custom-control custom-checkbox">
<input type = "checkbox" class="custom-control-input" id="illuminance">
<label class = "custom-control-label" for = "illuminance">Illuminance</label>
</div>
<div class ="custom-control custom-checkbox">
<input type ="checkbox" class="custom-control-input" id="button-state">
<label class ="custom-control-label" for = "button-state">Button-State</label>
<!---Downloading File using
Jquery with Buttons---->
<div class="form-group"><br>
<div class="col-md-1.9 text-center">
<button id="download" name="download" class="btn btn-warning" >Download</button><br>
</div>
</div>
// Downloading file into csv/json format.
$(document).ready(function() {
$("#download").click(function() {
var count = 0;
if($('#temperature').prop('checked')) count++;
if($('#illuminance').prop('checked')) count++;
if($('#button-state').prop('checked')) count++;
if(count > 1) {
window.location.href ='https://api.thingspeak.com/channels/899906/feeds.json?start=2019-11-14%2019:11:14&end=2019-11-18%2019:11:18';
}else{
// checking for one field being checked.
if($('#temperature').prop('checked')) count--;
if($('#illuminance').prop('checked')) count--;
if($('#button-state').prop('checked')) count--;
if(count < 1) {
window.location.href = ' https://api.thingspeak.com/channels/899906/fields/1.json?start=2019-11-15%2019:11:15&end=2019-11-18';
}
}
});
div class=“自定义控件自定义复选框”>
温度
照度
按钮状态
下载
//将文件下载为csv/json格式。
$(文档).ready(函数(){
$(“#下载”)。单击(函数(){
var计数=0;
如果($('#温度').prop('checked'))计数++;
如果($('#照度').prop('checked'))计数++;
if($('#按钮状态').prop('checked'))count++;
如果(计数>1){
window.location.href=https://api.thingspeak.com/channels/899906/feeds.json?start=2019-11-14%2019:11:14&end=2019-11-18%2019:11:18';
}否则{
//正在检查一个正在检查的字段。
如果($('#温度').prop('checked'))计数--;
如果($('#照度').prop('checked'))计数--;
如果($('#按钮状态').prop('checked'))计数--;
如果(计数<1){
window.location.href=https://api.thingspeak.com/channels/899906/fields/1.json?start=2019-11-15%2019:11:15&end=2019-11-18';
}
}
});
我们的想法是修改我的代码,下面是这个解决方案的示例
$('#temperature').click(function() {
var xcount = 0;
if($('#temperature').prop('checked')) xcount--;
if(xcount < 1) {
window.location.href ='https://api.thingspeak.com/channels/899906/fields/1.json';
}
});
});
$(“#温度”)。单击(函数(){
var xcount=0;
如果($('#温度').prop('checked'))xcount--;
如果(xcount<1){
window.location.href=https://api.thingspeak.com/channels/899906/fields/1.json';
}
});
});
请注意,我的URL参数发生了更改,原因很简单,因为如果用户选择复选框,我希望访问该复选框的一个字段,并且在我的文件格式中,如果该字段有日期,它将拉出日期格式以及该字段的数据。我还使用了一个名为REST client的扩展来查看Restful API的约束。为了您自己的利益,我认为最好重构代码,使其具有可维护性和可读性。