Search code examples
titaniumtitanium-mobileappceleratortitanium-alloy

Titanium JS: Error using Alloy data binding: 'undefined' is not an object (evaluating '__alloyId60.on')


I've created a new controller (search.js) in Titanium Alloy, within which I have referenced one of my collections:

search.js

var searchResults = Alloy.Collections.searchResults;

And then in my view (search.xml) I've created a TableView, and added the dataCollection attribute:

search.xml

<TableView id="resultsTable" dataCollection="searchResults">
    <TableViewRow title="{name}" />
</TableView>

In my controller, this collection gets populated with data via an online API, when the user does a search. In this code, results is a JSON object containing all the data:

search.js

_.each(results, function (item) {
   var beer = Alloy.createModel('searchResults', item);
   searchResults.push(beer);
});

When I run my app, I get the following error message:

"'undefined' is not an object (evaluating '__alloyId60.on')"

I don't see where I am going wrong, am I missing something?


Solution

  • I fixed this error by defining the global instance of my collection in my alloy.js file:

    Alloy.Collections.searchResults = Alloy.createCollection('searchResults');
    

    I found it from this answer on the Appcelerator developer forums.