sheetrock js回调函数 [英] sheetrock js callback function

查看:131
本文介绍了sheetrock js回调函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在sheetrock.js中使用回调选项?我试图从工作表中获取输出作为变量,以用作另一个函数的输入,但是由于我的JS知识有限,因此遇到了困难.有什么帮助吗?

How to use callback option in sheetrock.js? I'm trying to get the output from the sheetrock as a variable to be used as input for another function, but having difficulty due to my limited JS knowledge. Any help please?

    var d = new Date();
var month = new Array();
month[0] = "Jan";
month[1] = "Feb";
month[2] = "Mar";
month[3] = "Apr";
month[4] = "May";
month[5] = "Jun";
month[6] = "Jul";
month[7] = "Aug";
month[8] = "Sep";
month[9] = "Oct";
month[10] = "Nov";
month[11] = "Dec";
var n = month[d.getMonth()];
var y = d.getFullYear();
$("#value").sheetrock({
  url: 'https://docs.google.com/spreadsheets/d/1XSVP75fJkq34gLHhwIsEWOC3My-6xnbVURk4U_wotD0/edit#gid=0',
  query: "select C where B = "+ y +" and A = '"+ n +"'",
  callback: draw
});

function draw(data, sheetrock,response) {

   console.log(); // how to get the output from sheetrock as a variable?

}

推荐答案

这是sheetrock回调的工作方式:

Here is how sheetrock callback works :

function draw(error, options, response) {
  if (error) {
    console.log('fail');
  }
  else{
    console.log(response.html);
  }
}

要将其放入全局变量:

EDIT : To put it into a global variable :

var globalVar = {};
function draw(data, sheetrock,response) {
    globalVar.response = response.html;
}
function use(){
    $('#test').html(globalVar.response);
}

完整的示例: https://codepen.io/andreds/pen/baomVq

这篇关于sheetrock js回调函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆