0
声明JS-类型的字典时在QML JS实现中使用JS数组作为键,我可以这样写:如何在QML
property var dict1: ({})
property var dict2: { 'a':1, 'b':2, 'c':3 }
// property var dict3: { [0,0]:1, [1,4]:5, [2,4]:3 } // can't do this!
// but can do this.
Component.onCompleted: {
dict1[[0,0]] = 1
dict1[[1,4]] = 5
dict1[[2,4]] = 3
}
所以最后部分采用JS-阵列作为字典键。但是第3行(dict3)中的声明是不可能的。我不明白为什么一个符号不应该是可能的,如果预期的结果是可能的其他手段。
所以我的问题是:如何不需要Component.onCompleted
或类似的破解实例化dict
? 如果没有办法做到这一点,一个原因,将不胜感激。
谢谢!现在对我来说很有意义! – derM