Reputation: 12445
I am making feed reader appication on titanium alloy.
I have succeeded making table view and insert rows. then I can tap the each row.
However I am not sure how to get attributs of each rows.
please see the places.
// how can I get title // how can I get link?
I have developed some applications on titanium old version ,but still cant get used to alloy.
thanks alot.
index.js
if( !Ti.Network.online ) {
alert('Not online.');
}
var xhr = Ti.Network.createHTTPClient();
url = 'http://testsite.com.jp/testfeed.xml';
xhr.open('GET', url);
xhr.onload = function() {
Ti.API.info('onload()');
try{
var doc = this.responseXML.documentElement;
var items = doc.getElementsByTagName('item');
for (var i = 0; i < items.length;i++){
var title = items.item(i).getElementsByTagName('title').item(0).text;
var link = items.item(i).getElementsByTagName('link').item(0).text;
bgcolor = true;
var row = Alloy.createController("row",{
id: i+1,
title: title,
link: link,
bgcolor: bgcolor
}).getView();
$.tableByFav.appendRow(row);
}
}catch(e){alert(e);}
}
try{
xhr.send();
}catch( e ) {alert(e);
}
$.tableByFav.addEventListener('click',function(e){
Ti.API.info(e.rowData.title);//it shows null, how can I get the title?
Ti.API.info(e.rowData.linkData);// it shows null, how can I get the link?
})
$.index.open();
row.js
var args = arguments[0] || {};
$.row.backgroundColor = args.bgcolor ? "#faf8f5" : "#eee4db";
$.title.text = args.title;
$.linkData = args.link;
index.xml
<Alloy>
<TabGroup backgroundColor="white" >
<Tab id="byFav" title="fav" icon="KS_nav_views.png">
<Window>
<TableView id="tableByFav" />
</Window>
</Tab>
<Tab id="byDate" title="log" icon="KS_nav_views.png">
<Window>
<TableView id="tableByDate" />
</Window>
</Tab>
<Tab id="byCat" title="cat" icon="KS_nav_views.png">
<Window>
<TableView id="tableByCat" />
</Window>
</Tab>
</TabGroup>
</Alloy>
row.xml
<Alloy>
<TableViewRow id="row">
<Label id="title">Menu</Label>
<ImageView id="image" image="/image1.jpg" />
</TableViewRow>
</Alloy>
Upvotes: 2
Views: 1459
Reputation: 223
I added some generic code because your web service was not working. To use the rowData you would need to set the row object inside your row controller. Below is a sample working version.
index.js
var data = [];
for (var x = 0; x < 10;x++){
var args = {
id: x,
title: 'my Title',
image: 'my image url'
};
var row = Alloy.createController("row", args).getView();
data.push(row);
}
$.tableByFav.setData(data);
$.tableByFav.addEventListener('click',function(e){
Ti.API.info(e.rowData.id);
Ti.API.info(e.rowData.title);
Ti.API.info(e.rowData.image);
})
$.index.open();
row.js
var args = arguments[0] || {};
$.row.id = args.id;
$.row.title = args.title;
$.row.image = args.image;
row.xml
<Alloy>
<TableViewRow id="row">
<Label id="title"/>
<Label id="image"/>
</TableViewRow>
</Alloy>
Upvotes: 0
Reputation: 7028
When you are working with Alloy you have to keep in mind that objects passed to eventListeners are still plain Titanium objects. To achieve something similar to what you need try this:
In row.js add one line:
$.row.args = args;
Then in your eventListener you can try this:
$.tableByFav.addEventListener('click',function(e){
Ti.API.info(e.row.args);
});
Which will output to console something similar to this JSON:
[INFO] {
[INFO] bgcolor = 1;
[INFO] id = 1;
[INFO] link = "http://test1.com";
[INFO] title = "Test 1";
[INFO] }
Upvotes: 2