Passing data to a new page

Events happening in the community are now at Drupal community events on www.drupal.org.
Posted by JayCally on August 25, 2010 at 4:07pm

I am pulling in data from a Drupal JSON service and displaying in a tableview. Working great. When you click a row, the full node is displayed in a webview. Works good but I'd like to display the node in the app instead of a webview. I tweaked things and now when you click a row, a new page loads which gets the node with node.get service.

The issue I'm having is I want to pass the node ID to the new page to display its content. I've used the kitchen sink example to pass text to the page which works. I can pass '236' (a node ID) to view.nid = "236"; in page.js which will pull the node but I need to pass data[c].nid from each row so the correct node loads for each teaser.

How can I pass data[c].nid to another page?

Categories: , ,

Comments

Got it to pass the nid to

Posted by JayCally on August 25, 2010 at 6:12pm

Got it to pass the nid to view.nid = " " but I have one issue. Its only sending the first node in the JSON service when I tap on any teaser. Also notice that its doing the same with the window title.

CODE

for (var c=0;c<data.length;c++)
{
// creates right arrow indicator
var row = Ti.UI.createTableViewRow();
row.rightImage = '../images/indicator.png';

var label = Ti.UI.createLabel({
 text: data[c].nid,
 color: '#333333',
 shadowColor:'#FFFFEF',
 shadowOffset:{x:0,y:1},
 textAlign:'left',
 top:10,
 left:10,
 width:260,
 height:60,
 font:{fontWeight:'bold',fontSize:16}
});
if (Titanium.Platform.name == 'android') {
 label.top = 10;
}
row.add(label);
row.url = 'page2.js';
label.addEventListener('click',function(e)
{
 Ti.API.info(e.rowData);

if (e.rowData.url)
{
var win = Titanium.UI.createWindow({
url:e.rowData.url,
title:label.text,
barColor:'#919eab'
});
win.node = function(e)
{
var nodeid
nodeid = label.text
return nodeid
};
Titanium.UI.currentTab.open(win,{animated:true});
}
});

}

If I understand you right.

Posted by rickyd1 on March 30, 2011 at 8:42am

If I understand you right. You are only passing the first item from the list to your next .js file.

I have had this issue before. You need to pull the variable for each row.

something like
var label = Ti.UI.createLabel({
text: data[c].nid,
color: '#333333',
shadowColor:'#FFFFEF',
shadowOffset:{x:0,y:1},
textAlign:'left',
top:10,
left:10,
width:260,
height:60,
font:{fontWeight:'bold',fontSize:16}
});
if (Titanium.Platform.name == 'android') {
label.top = 10;
}
row.add(label);

row.nodeId = data[c]['nid']; // you need to define the node id for that row

row.url = 'page2.js';

Then....

var tableview = Titanium.UI.createTableView({
data:data,
style:Titanium.UI.iPhone.TableViewStyle.PLAIN,
backgroundColor:'white'
});

tableview.addEventListener('click',function(e)
{
Ti.API.info(e.rowData);
if (e.rowData.url)
{
var win = Titanium.UI.createWindow({
url:e.rowData.url,
title: e.rowData.label.text, // pass the title of the node by pulling the text from the label
passedId: e.rowData.nodeId // pass the node id from the row to the next .js file
});
Titanium.UI.currentTab.open(win,{animated:true});
}
});
win.add(tableview);

BTW, I am using D6 with the modified JSON from an earlier post by Sumitk. If you haven't checked out his post you should it is easy to use.

I think that should work.
Let me know if any of this helps.

what DRUPAL modules...

Posted by irishgringo on March 29, 2011 at 1:08pm

are you using. I am guessing D6 JSON services?

Titanium API

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

AltStyle によって変換されたページ (->オリジナル) /