variables不被保留
Alrighty。
我的问题是与Javascript对象itemList
和priceList
– 他们没有妥善保存到priceList
.then()
部分。
以下是我遇到的问题:
var stmt = `SELECT * FROM SRV${msg.guild.id}`; var itemList = {}; var priceList = {}; var num = -1; sql.each(stmt, function(err, row) { num++ if(row.items!="ITEMS") { itemList[num] = row.items; } if(row.prices!="PRICES") { priceList[num] = row.prices; } console.log("---------\n" + JSON.stringify(itemList, null, 4) + "\n" + JSON.stringify(priceList, null, 4)); }) .then((itemList, priceList) => { console.log("----E----\n" + JSON.stringify(itemList, null, 4) + "\n" + JSON.stringify(priceList, null, 4) + "\n----E----"); let cmd = require("./itemsPROCESS.js"); cmd.run(transfer, msg, args, itemList, priceList); });
这是它输出的重要部分:
我试过使用string,而不是Javascript对象,但它似乎并不喜欢,也输出相同。
5
和undefined
部分应该类似于它上面的位,但它不。
这可能与零部件有关吗? 如果是这样,这是否意味着它将无法true
– false
– undefined
等?
删除参数itemList
和priceList
,你的代码应该没问题。
你在itemList
函数中引用的itemList
实际上是由SQL承诺解决的。
.then(() => {...});
您正在使用全局范围的itemList
和priceList
,因此不要在当地的范围内重新定义它们。 从那里删除那些参数
.then(() => { console.log("----E----\n" + JSON.stringify(itemList, null, 4) + "\n" + JSON.stringify(priceList, null, 4) + "\n----E----"); let cmd = require("./itemsPROCESS.js"); cmd.run(transfer, msg, args, itemList, priceList); });