Hello, I am completely new to working with Titanium and currently, in my project, I am iterating through JSON data that defines the titles and content of my app pages. Take a look at this function:
xhr.onload = function() {
try {
var myPages = JSON.parse(this.responseText);
for (var c=0;c<myPages.length;c++){
var title = myPages[c].title; // page title
var content = myPages[c].content; // page content
I have managed to add my page titles as labels within TableViewRow:
var row = Ti.UI.createTableViewRow({hasChild:true,height:Ti.UI.SIZE,backgroundColor:bgcolor});
// Creating a vertical layout view to accommodate all the titles
var post_view = Ti.UI.createView({
height: Ti.UI.SIZE,
layout:'vertical',
left:5,
etc..
});
// Label creation for article titles
var label_title = Ti.UI.createLabel({
text:title,
left:5,
etc...
});
// Adding the article titles to the view
post_view.add(label_title);
// Adding the vertical layout view to the row
row.add(post_view);
row.className = 'item'+c;
data[c] = row;
Everything seems to be functioning properly as I can see my page titles in each row of the table. However, when a user clicks on a title, I intend for the app to open a new window displaying the content of the corresponding page. This is where I am facing challenges!
To address this issue, I tried implementing the following function:
// Setting up event listeners for the rows
row.addEventListener('click', function(){
Titanium.API.info('row has been clicked');
// View creation for article content
var articleView = Titanium.UI.createView({
height: Ti.UI.SIZE,
layout:'vertical',
left:5,
etc..
});
var t = Ti.UI.iPhone.AnimationStyle.FLIP_FROM_LEFT;
win.animate({view:articleView,transition:t});
var articleViewContent = Ti.UI.createLabel({
text:content,
left:5,
etc..
});
// Adding the content to the view
articleView.add(articleViewContent);
});
}
// Creating the tableView and incorporating it into the window.
var tableview = Titanium.UI.createTableView({data:data,minRowHeight:58});
win.add(tableview);
}
catch(E){
alert(E);
}
};
Although I am able to receive a response upon clicking the title, I am struggling to display the corresponding content in the new view. I believe the counter should retain this information (from the time the titles were generated) but I am unsure how to access it.
I am feeling quite lost at the moment and worry that I might be misunderstanding some essential concepts here. Considering that I am relatively new to JavaScript, I would appreciate any guidance or suggestions to help me enhance my skills!
(I have included 'etc..' in the code to keep things concise)