Skip to content

Instantly share code, notes, and snippets.

@viezel
Created February 16, 2013 21:21
Show Gist options
  • Save viezel/4968784 to your computer and use it in GitHub Desktop.
Save viezel/4968784 to your computer and use it in GitHub Desktop.
Alloy bug: Global collection is overriding others?
var collection = Alloy.Collections.collection;
var openAddItem = function(){
var win = Alloy.createController("CollectionDetail").getView();
win.open();
}
function dataTransform(model) {
var transform = model.toJSON();
transform.title = transform.first + " " + transform.last;
return transform;
}
//init - get the data
collection.fetch();
<Alloy>
<Collection src="collection"/>
<Window id="win">
<RightNavButton>
<Button onClick="openAddItem">Add</Button>
</RightNavButton>
<SearchBar id="search" />
<TableView id="table" dataCollection="collection" dataTransform="dataTransform">
<TableViewRow class="row" model="{id}" >
<Label id="titlel" class="rowTitle" text="{name}"/>
</TableViewRow>
</TableView
</Window>
</Alloy>
<Alloy>
<TabGroup id="tabgroup">
<Tab id="tab1" title="Tips">
<Require src="Tips" id="tipsWindow" title="Tips"/>
</Tab>
<Tab id="tab2" title="Collections">
<Require src="Collections" id="MyCollections" title="My Collections"/>
</Tab>
</TabGroup>
</Alloy>
var tipCollection = Alloy.Collections.tip;
var openAddItem = function(){
var window = Alloy.createController("TipDetail").getView();
window.open();
}
$.win.addEventListener('close', function() {
// destroy global collection/model for our bindings - memory leaks.
$.destroy();
});
//sorting by date
tipCollection.comparator = function(entry1, entry2) {
return entry1.get('modifiedDate') > entry2.get('modifiedDate') ? -1 : 1;
}
//DATA transform of tableView
function dataTransform(model) {
var transform = model.toJSON();
transform.modifiedDate = moment(transform.modifiedDate,'YYYY-MM-DD HH:mm:ss').fromNow();
transform.city = transform.city + ", " + transform.country;
return transform;
}
var refresh = function(){
// update data from remote
tipCollection.fetch();
}
//init - get the data
tipCollection.fetch();
<Alloy>
<Collection src="tip"/>
<Window id="win">
<LeftNavButton>
<Button onClick="refresh">Refresh</Button>
</LeftNavButton>
<SearchBar id="search" />
<TableView id="table" dataCollection="tip" dataTransform="dataTransform">
<TableViewRow class="row" model="{id}" >
<Label id="titlelabel" class="rowTitle" text="{name}"/>
<Label class="rowSubTitle" text="{city}"/>
<Label class="dateLabel" text="{modifiedDate}"/>
</TableViewRow>
</TableView>
</Window>
</Alloy>
@felixaa
Copy link

felixaa commented Feb 1, 2016

Any solutions to this issue yet? I'm kind of stuck with the same problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment