Using node.get

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
JayCally's picture

I'm using Sumitk's great example on using Titanium with Drupal JSON service. I can pull in view data and display it correctly and link to the node in a webview. I'd like to just get a node. I've modified the views.get example to get the node but it isn't displaying.

I have a tableview with links to different durpal content like a view of nodeA. One title I want to link to a node. I it linking to 'page.js' which has the below code.

var url = 'http://localhost:8888/testsite/services/json';

var win = Titanium.UI.currentWindow;
win.backgroundColor = '#dce0e4';

var data = [];

var view = new Object;
view.method = 'node.get';
view.nid = '25475';

var xhr = Titanium.Network.createHTTPClient();
xhr.open("POST",url);

// sending xhr call for view
xhr.send({data: JSON.stringify(view)});

xhr.onload = function() {

Ti.API.info(this.responseText);

var data = JSON.parse(this.responseText);

Ti.API.info(data);

var label = Titanium.UI.createLabel({
text: data[c]['body'],
color: '#333333',
textAlign:'left',
top:10,
left:10,
width:260,
height:60,
font:{fontWeight:'bold',fontSize:16},
});

currentWindow.add(label);

}

Any thoughts on why the content won't display.

Comments

I don't know if you figured

rickyd1's picture

I don't know if you figured this out since it is so old, but I ran into a similar situation. So I figured I would share my situation.

In my example I modified Sumitk's code - similar to above - and put it in a scrolling view (From Titanium Kitchen sink).

When I loaded the app, it had errors.

Problem 1: I was not declaring [c]

in Sumitk's example we use the following to pull our rows from our view.get method

for (var c=0;c < data.length;c++)

However, in my case I didn't need to do this. So I just wanted to present the node title and body since there was only one instance. There for this

text: data[c]['title'],

would become

text: data['title'],

There was no need to use [c] since I never declared it.

Problem 2: I never set my permissions correctly and the I would get an access denied error. Make sure the user has permission to "load node data"

Hope that helps some of you out there. Remember if you are not logged in and you get a access denied in the titanium logs check your Drupal permissions. I swore it was setup right because my views.get was working, but each one has it's own permissions.

Titanium API

Group organizers

Group notifications

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