Issue
Collection instance binding does not work properly.
Expected Result
All Models should be displaying in the ListView
Actual Result
Only the last added model is showing in the ListView
Model
exports.definition = {
config : {
columns : {
"id" : "INTEGER PRIMARY KEY AUTOINCREMENT",
"name" : "STRING"
},
adapter : {
type : "sql",
idAttribute : "id",
collection_name : "adidas"
}
}
};
Controller
var i = 5;
while (i > 0) {
var model = Alloy.createModel("adidas", {
"name" : "CRAZY LIGHT FOUR" + i
});
// add model to collection which will in turn update the UI
$.sports.add(model);
// save the model to SQLite
model.save();
i--;
}
$.sports.fetch();
Ti.API.info($.sports.toJSON());
$.index.open();
View
<Alloy>
<Collection id="sports" src="adidas" instance="true"/>
<Window fullscreen="true" dataCollection="$.sports" backgroundColor="white">
<ListView>
<ListSection>
<ListItem title="{name}" accessoryType="Ti.UI.LIST_ACCESSORY_TYPE_DISCLOSURE">
</ListSection>
</ListView>
</Window>
</Alloy>
Hi It's not a bug. It's working as expected. You just need to change something in your index.xml file. The following code is the solution. DataCollection is not window object. it should be set in listview.
Testing Environment:
Titanium SDK: 3.2.3, 3.3.0.RC, Titanium CLI: 3.3.0 –rc, iOS SDK: 7.1 Alloy: 1.4.0 OS X Version: 10.9.3, Appcelerator Studio: 3.2.3Test Code
Fixed in 3.3.0.GA.