我有四个看起来类似于这些的文件:
索引.xml
<Alloy>
<Window>
<View class="container">
<View id="report">
<!-- Adds a textfield for name entry -->
<Require type="view" src="textfield" id="name"/>
<Button id="checkNameValue" title="Check Value" width="100" height="40" onClick="checkname"/>
</View>
</View>
</Window>
</Alloy>
index.js
function checkname(e) {
alert("Your name is " + $.name.getView('nameTextField').value);
}
文本字段.xml
<Alloy>
<View id="nameView">
</View>
</Alloy>
文本字段.js
var nameTextField = Titanium.UI.createTextField({
hintText:"Type your name",
height:40,
width:300,
top:20,
borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
$.nameView.add(nameTextField);
当我尝试单击 Button 来读取名称值时,出现错误:
message = "'undefined' is not an object (evaluating $.name.getView(\"nameTextField\").value')";
出了什么问题,我该如何解决?