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

dataFilter function being called twice on collection.fetch()

$
0
0

Given the code below can anyone tell me why the filterFunction is being called twice? It is called twice every time fetch() is called. Is this normal behavior?

locations.xml

<Alloy>
    <Window id="win" title="Buy Locations" class="container" layout="vertical" 
            fullscreen="true" navBarHidden="true" barColor="black">
        <SearchBar id="searchBar" barColor="#7A7979" showCancel="true" 
            hintText="search" height="44" top="0" width="Ti.UI.FILL"/>
        <ListView id="list" defaultItemTemplate="location">
            <Templates>
                <ItemTemplate name="location" height="70">
                    <View height="70" width="50" left="0">
                        <Label class="mapIcon"/>
                    </View>
                    <View left="50" top="0" layout="vertical" width="Ti.UI.FILL">
                        <Label bindId="name" class="name" left="0" top="5" 
                            height="30" width="Ti.UI.FILL"/>
                        <Label bindId="address" class="address" left="0" top="0" 
                            height="20" width="280"/>
                    </View>
                </ItemTemplate>
            </Templates>
 
            <ListSection id="section" dataCollection="retailers" 
                    dataTransform="doTransform" dataFilter="filterFunction">
                <ListItem template="{template}" name:text="{NAME}" 
                    address:text="{STREET_ADDRESS}"/>
            </ListSection>
        </ListView>
    </Window>
</Alloy>
locations.js
var args = arguments[0] || {};
var brewerID = args.brewerID || '';
var filterCriteria = "";
 
var retailers = Alloy.Collections.retailers; 
retailers.fetch();
 
function doTransform(model) {
    var o = model.toJSON();
    o.template = "location";
    o.STREET_ADDRESS = o.STREET_NUM + " " + o.STREET + ", " + o.TOWN + ", " + 
        o.STATE + " " + o.ZIP;
    return o;
}
 
// filter collection
function filterFunction(c) {
    Ti.API.info("===> In filterFunction");
    var collection = c.where({ID_BREWER: brewerID});
    if(filterCriteria.length > 0) {
        Ti.API.info("filtering collection by:" + filterCriteria);
    }
    return collection;
}
 
$.searchBar.addEventListener("change", function(e) {
    var val = e.value;
    Ti.API.info("searchBar value: " + val);
 
    filterCriteria = val;
    retailers.fetch();
});
 
$.searchBar.addEventListener("cancel", function(e) {
    $.searchBar.value = "";
    $.searchBar.blur();
});
Thanks in advance!

Viewing all articles
Browse latest Browse all 8068

Trending Articles



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