在 Qml 文件中,代码如下:
StackView {
id: stackView
anchors.right: parent.right
width: parent.width/2-20
initialItem:patientdetail
Component{
id:patientdetail
Column {
id:detailcolumn
spacing: 2
anchors.right: parent.right
width: parent.width/2-20
Label {
id: label
color: "#ffffff"
text: qsTr("User ID")
}
TextField {
id: textField_id
readOnly: true
placeholderText: qsTr("")
}
}
}
Component{
id:component2
//...other component will add to stackview
}
}
Run Code Online (Sandbox Code Playgroud)
我想通过 JS 函数(在同一个文件中)更改 TextField 的文本,例如:
function updatedetail(clear,rowindex){
if(clear){
textField_id.text="";
}
else{
textField_id.text=jsonModel1.model.get(rowindex).id;
}
}
Run Code Online (Sandbox Code Playgroud)
但是有一个错误:
ReferenceError: textField_id 未定义
错误发生在哪里?