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

Dynamic ListView with Templates, avoid loop, or other UI element?

$
0
0

I'm trying to create a ListView that loads the content directly from my web service, my result it's always formatted this way:

var result = {total:2,data:[
     {name:'Edu',age:26,image:'http://someurl.com/edu.png'},
     {name:'Mike',age:24,image:'http://someurl.com/mike.png'}
]}
This is my ListItem Template:
<ListView id="list">
    <ItemTemplate name="users" height="30">
        <View>
            <ImageView left="12" bindId="image"/>
            <Label left="62" bindId="name"/>
            <Label left="62" bindId="age"/>                     
        </View>
    </ItemTemplate>
</ListView>
What I want with this is avoid creating a for loop to work the received result to set data in the ListView, actual code:
var data = [];
for(var i in result.data) {
    data.push({
        "image":{image:result.data[i].image,
        "name":{text.result.data[i].name,
        "age":{text.result.data[i].age
    });
}
$.list.sections[0].setItems(data);
Other question, about performance:

My intention is to work about 600 rows the fastest way, and I think my actual solution is slowing down the app:

for(var i in result.data) {
 
    var user = Alloy.createController('ui/user',{
        name:result.data[i].name,
        age:result.data[i].age,
        image:result.data[i].image,
        touch:function() {
            //this will add an click event listener on ui/user view element
        }
    }).getView();
 
    $.scrollview.add(user);
}

Viewing all articles
Browse latest Browse all 8068

Trending Articles



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