【发布时间】:2014-06-17 23:02:12
【问题描述】:
有什么方法可以在QML 中获取项目类?我知道objectName 和id 等,但它看起来有点奇怪而且不太舒服。这就是我需要的:
ComboBox {
id: comboBox
}
TextField {
id: textField
}
function getValue(item) {
switch(item.???) { //what property can I use here?
case 'ComboBox':
return item.model.get(item.currentIndex).value;
case 'TextField':
return item.text;
}
}
使用互联网上许多文章中描述的objectName 可能会模棱两可且过度,例如:
ComboBox {
id: comboBox
objectName: "ComboBox"
}
TextField {
id: textField
objectName: "ComboBox" /// oops!!
}
function getValue(item) {
switch(item.objectName) {
case 'ComboBox':
return item.model.get(item.currentIndex).value;
case 'TextField':
return item.text;
}
}
【问题讨论】:
-
这种信息很可能在解析后被删除了,因为这些名称只是声明了组件的文件的名称......
标签: javascript qt qml qtquick2