gpt4 book ai didi

javascript - 从 QT 中的 QML 中的 JS 返回值失败

转载 作者:行者123 更新时间:2023-12-01 02:11:57 25 4
gpt4 key购买 nike

我正在尝试简单的函数,但函数没有返回任何内容,但是“控制台日志返回了正确的值,请问我的代码有什么问题吗?...

JS:

function potentieldated(Pimmatriculation, Pdateinstallation)
{
var db = dbGetHandle()
db.transaction(function (tx) {
var results = tx.executeSql(
'SELECT * FROM (SELECT * FROM (SELECT date_etape, heure_depart, heurecellule, cyclecellule from flight_log where immatriculation=? and date_etape <= ? ORDER by heure_depart desc) ORDER by date_etape desc limit 1)UNION ALL SELECT "0", "0", "0", "0" LIMIT 1 ' , [Pimmatriculation, Pdateinstallation])
var heurecellule= results.rows.item(0).heurecellule;
var cyclecellule= results.rows.item(0).cyclecellule;
console.log("heurecellule JS " + heurecellule);
console.log("cyclecellule JS "+ cyclecellule);
return {heurecellule:heurecellule,cyclecellule:cyclecellule}
})
}

QML 表格:

var potentiel= JS.potentieldated(stringVariable,dateaircraftpartinstallation)
var heure = potentiel.heurecellule
var cycle = potentiel.cyclecellule
console.log("heure "+heure)
console.log("cycle "+cycle)

控制台.日志消息:

qml: heurecellule JS 14010.25
qml: cyclecellule JS 4672
qrc: Cannot read property 'heurecellule' of undefined

你能帮我吗?

非常感谢

最佳答案

您没有从正确的函数返回值:

function potentieldated(Pimmatriculation, Pdateinstallation) {
var heurecellule = 0
var cyclecellule = 0
var db = dbGetHandle()
db.transaction(function (tx) {
var results = // ...
heurecellule = results.rows.item(0).heurecellule;
cyclecellule = results.rows.item(0).cyclecellule;
})
return {heurecellule:heurecellule,cyclecellule:cyclecellule}
}

关于javascript - 从 QT 中的 QML 中的 JS 返回值失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49697520/

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