我在用sqlite提取总和时遇到了麻烦,它在我的javascript代码中返回了未定义的内容。你能帮我么?这是我的密码。
这是我的index.js代码
function displayExpenses(results) {
var length = results.rows.length;
for(i = 0; i < length; i++) {
var item = results.rows.item(i);
var parsedMon = parseInt(item.mon_value);
var moneyVal = (parsedMon).toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
console.log(moneyVal);
}
}
`````
here is my sqlite code
```
fetchExpenses: function(displayExpenses) {
databaseHandler.db.readTransaction(
function(tx) {
tx.executeSql(
"SELECT SUM (mon_value) FROM money WHERE mon_type = '-'",
[],
function(tx, results) {
displayExpenses(results);
}
);
}
);
}
[1]: https://i.stack.imgur.com/C1b19.png
[2]: https://i.stack.imgur.com/UgI6F.png
[3]: https://i.stack.imgur.com/82UN5.png
答案 0 :(得分:1)
item.mon_value可能无法工作,除非您给它这样的别名:
rn = range(0,10**18)
it = iter(rn) # could be created from other source, used as example
ls = list(range(0,15))
print(rn)
print(ls)
print(it)
> range(0, 1000000000000000000)
> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
> <range_iterator object at 0x7f20cd3866f0>
#I will put some breaks so when you try it, it will stop some day haha
for i in it:
if(i<20):
print(i)
else:
break
for i in rn:
if(i<20):
print(i)
else:
break
您可能还需要查看以下内容:How can I assign a name to the SUM column?