Titanium FaveBook教程无法记录

时间:2014-02-23 10:06:55

标签: titanium

环境信息:

Titanium命令行界面,CLI版本3.2.1,Titanium SDK版本3.2.1.GA 运行Ubuntu 13.10 Android模拟器 Studio:Build:jenkins-titanium-rcp-master-95(origin / master) 日期:2014年2月4日,11:47:38

我在这里使用教程:

http://docs.appcelerator.com/titanium/latest/#!/guide/Creating_Your_First_Titanium_App

大多数工作都在运行,直到最后我添加“允许用户添加书籍”逻辑。

views / addbook.xml如下所示:

<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>

controllers / addbook.js如下所示:

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

根据Titanium论坛上的建议,http://developer.appcelerator.com/question/162650/having-problems-with-the-creating-your-first-titanium-app-example-at-httpdocsappceleratorcomtitaniumlatestguidecreat让我了解最初的问题。

进行更改后,我得到的下一个错误是:

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

欢迎任何关于我做错事的帮助,谢谢!

1 个答案:

答案 0 :(得分:0)

var myBooks = Alloy.Collection.books; 

应该是

var myBooks = Alloy.Collections.books;

之后它的工作。