Question

I'm writing a simple app in which i want to try Alloy data binding,

I have a model Region all set, I create a singleton by adding it in the markup

<Alloy>
    <Collection id="regions" src="Region" instance="true"/>
    <Window  id="regionWin">

    <TableView id="table" dataCollection="Region">
            <TableViewRow title="{regionName}" />           
    </TableView>

    </Window>
</Alloy>

using the model in the controller just works fine

var c = Alloy.createCollection('Region');

var aRegion =  Alloy.createModel('Region', { '_id':'123', 'regionName':'Lazio', 'version': 43});
aRegion.save();

but in the XML nor giving the id 'regions' or the collection name 'Region' as value to the TableView attribute 'dataCollection' i got results.

the error is always

Can't find variable: Region at RegionScreen.js (line 34) or Can't find variable: regions at RegionScreen.js (line 34)

any suggestions?

Was it helpful?

Solution

In dataCollection you should use $.regions ($. plus the id you defined in the Collection element).

<Alloy>
    <Collection id="regions" src="Region" instance="true"/>
    <Window  id="regionWin">

        <TableView id="table" dataCollection="$.regions">
            <TableViewRow title="{regionName}" />           
    </TableView>

    </Window>
</Alloy>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top