0
votes

I am new to using Appcelerator and having some difficulty performing a task that should be relatively simple. I am trying to retrieve an RSS feed and then display each entry in a TableView; grabbing the entries is working fine but I cannot seem to figure out how to then pass the results on to the TableView element.

I have found a lot of tutorials that tackle this for Titanium (usually 2+ years old) but I really want to use Alloy. I learned how to iterate over items in a Model but in this case we're fetching RSS data.

Here is the code I have so far:

index.js

var data =[];
var x = 0;
var xhr = Ti.Network.createHTTPClient();
xhr.open("GET", "https://somewhere.org/feed");
xhr.onload = function() {
    try {
        var doc = this.responseXML.documentElement;
        var items = doc.getElementsByTagName("entry");
        var x = 0;
        for(var c = 0; c<items.length;c++) {
            var item = items.item(c);
            var name = item.getElementsByTagName("name").item(0).text;
            var row = {'name' : name};
            data[x++] = row;
        }
    } catch(E) {
        alert(E);
    }
};
xhr.send();
$.index.open();

index.xml

<Alloy>
<Window class="container">
    <TableView>
        <TableViewRow title="{name}"></TableViewRow>
    </TableView>
</Window>

Any help would be appreciated.

1

1 Answers

0
votes

In the Codestrong example, it appears that they (Appcelerator) create the rows in the controller code. So, the tableview is defined in the xml with an id to reference it. The tableviewrows are then created through a loop and an array is made. At the end, the table's data is set to the array of tableviewrows.

I like to reference the Codestrong example because you can get it from the appropriate app store for your device and then get the source code for it from github. Makes it nice to follow along and see it function and then observe the code behind it. https://github.com/appcelerator/Codestrong

In the lib/ui, tableviewrows are defined for various parts of the app.