Titanium 钛合金FaveBook教程不';我不能像文件所记载的那样工作
环境信息: Tianium命令行界面,CLI版本3.2.1,Tianium SDK版本3.2.1.GA 运行Ubuntu 13.10 模拟器 工作室:构建:jenkins-titanium-rcp-master-95(源代码/主代码) 日期:2014年2月4日11:47:38 我在这里学习教程: 几乎所有的东西都在工作,直到最后我添加了“允许用户添加书籍”逻辑 views/addbook.xml如下所示:Titanium 钛合金FaveBook教程不';我不能像文件所记载的那样工作,titanium,Titanium,环境信息: Tianium命令行界面,CLI版本3.2.1,Tianium SDK版本3.2.1.GA 运行Ubuntu 13.10 模拟器 工作室:构建:jenkins-titanium-rcp-master-95(源代码/主代码) 日期:2014年2月4日11:47:38 我在这里学习教程: 几乎所有的东西都在工作,直到最后我添加了“允许用户添加书籍”逻辑 views/addbook.xml如下所示: <Alloy> <Window class="containe
<Alloy>
<Window class="container">
<View layout="vertical">
<TextField id="titleInput" hintText="Title..."></TextField>
<TextField id="authorInput" hintText="Author..."></TextField>
<Button id="insertBookButton" onClick="addBook">Add</Button>
</View>
</Window>
</Alloy>
var myBooks = Alloy.Collection.books;
function addBook(event) {
var book = Alloy.createModel('books', {
title : $.titleInput.value,
author : $.authorInput.value
});
myBooks.add(book);
book.save();
// Close the window.
$.addbook.close();
}
然而,当我运行应用程序时,我得到:
[ERROR] : TiExceptionHandler: (main) [1237,1237] ----- Titanium Javascript Runtime Error -----
[ERROR] : TiExceptionHandler: (main) [1,1238] - In alloy/controllers/index.js:34,13
[ERROR] : TiExceptionHandler: (main) [12,1250] - Message: Uncaught ReferenceError: addBook is not defined
[ERROR] : TiExceptionHandler: (main) [0,1250] - Source: addBook ? $.__views.addBook.addEventListener("click", addBook) : _
[ERROR] : V8Exception: Exception occurred at alloy/controllers/index.js:34: Uncaught ReferenceError: addBook is not defined
根据钛论坛上的建议,我将围绕最初的问题工作
做出更改后,我得到的下一个错误是:
TiExceptionHandler: (main) [4076,4076] ----- Titanium Javascript Runtime Error -----
[ERROR] : TiExceptionHandler: (main) [2,4078] - In alloy/controllers/addbook.js:47,35
[ERROR] : TiExceptionHandler: (main) [19,4097] - Message: Uncaught TypeError: Cannot read property 'books' of undefined
[ERROR] : TiExceptionHandler: (main) [1,4098] - Source: var myBooks = Alloy.Collection.books;
[ERROR] : V8Exception: Exception occurred at alloy/controllers/addbook.js:47: Uncaught TypeError: Cannot read property 'books' of undefined
欢迎任何关于我做错了什么的帮助,谢谢
var myBooks = Alloy.Collection.books;
应该是
var myBooks = Alloy.Collections.books;
之后它就开始工作了。您是直接从教程中复制了错误的行,还是手动输入的?你提到的那行确实是
var myBooks=Alloy.Collections.books代码>('collections'复数,而非单数)。我现在不记得了,我需要回去看看。