Titanium JIRA Archive
Appcelerator Community (AC)

[AC-1564] Alloy - collection instance does not work properly on ListView data binding?

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionFixed
Resolution Date2014-07-29T06:52:01.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsAlloy
Labelscore, ios
ReporterDavid He
AssigneeMauro Parra-Miranda
Created2014-07-03T04:51:02.000+0000
Updated2016-03-08T07:38:01.000+0000

Description

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>

Comments

  1. Motiur Rahman 2014-07-07

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

    Test Code

       <Alloy>
           <Collection id="sports" src="adidas" instance="true"/> 
           <Window fullscreen="true"  backgroundColor="white">
               <ListView>
                   <ListSection dataCollection="$.sports">
                       <ListItem title="{name}" accessoryType="Ti.UI.LIST_ACCESSORY_TYPE_DISCLOSURE">
                   </ListSection>
               </ListView>
           </Window>
       </Alloy>
       
  2. Mauro Parra-Miranda 2014-07-29

    Fixed in 3.3.0.GA.

JSON Source