javascript - Is there Lambda support in QML files?
问题描述
I have something like this:
var arr = []
arr.indexOf(element => element.includes(''))
QtCreator gives error for this. My Qt version is 5.12 and I'm using QtCreator 4.8.
Can I use this kind of lambda expressions in QML?
解决方案
这只是一个 QtCreator 错误,箭头函数在 Qt 5.12 及更高版本中受支持。QtCreator 从 4.9 版本开始正确支持它们并停止显示警告(QTCREATORBUG-21301和QTCREATORBUG-20341。请参阅4.9 更改日志)。
但是,在您的情况下,正如 folibis 所说,findIndex
如果您想提供谓词,则需要。在 5.12 中确实可以使用,支持的功能的页面不是很可靠。
Qt 5.12 应该支持大多数标准的 ECMAScript 函数,查看MDN以获取参考并尝试使用您的 Qt 代码。
{
let arr = ['a', 'ab', 'abc', 'abcd'];
let index = arr.findIndex(element => element.includes('c'));
let abcIsPresent = arr.includes('abc');
print(index, abcIsPresent);
}
此代码在 Qt 5.12 中运行并输出2 true
。
推荐阅读
- postgresql - 使用 POSTGIS 操作制作有效的大几何图形
- javascript - 静态下拉菜单在 Bootstrap 中不起作用
- amazon-web-services - 如何使用 terraform 在 LocalStack 上创建 EC2 实例?
- reactjs - 期望一个组件被渲染
- gradle - 如何在各种情况下将 Maven (Nexus) 凭据传递给 build.gradle 文件?
- node.js - 我无法导入没有错误的模块
- python - argparse:str 对象没有属性
- python - 如何在 Julia 中替换使用 python 的属性
- android - Retrofit2 发送 Bearer Token
- excel - 当一个单元格有数组数据时,从 Excel 中计算数据