Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Alloy - collection instance does not work properly on ListView data binding?

$
0
0

Issue - the code snippet in controller does only insert one list item into the list view, why was that? Any idea?

Environment

iOS 7.1 Ti SDK 3.2.3 Alloy 1.4.0

Model

adidas.js

exports.definition = {
    config : {
        columns : {
            "id" : "INTEGER PRIMARY KEY AUTOINCREMENT",
            "name" : "STRING"
        },
        adapter : {
            type : "sql",
            idAttribute : "id",
            collection_name : "adidas"
        }
    }
};

Controller

index.js

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

index.xml

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

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>