1

I am getting started with Drupalgap and trying to access nodes on my Drupal site by node ID from within Drupalgap. I have checked the Node and Node Services documentation. I thought I could use the node_page_view(nid) function like this:

function mymodule_sample_page() {
  try {
    node_load(11, {
        success:function(node){
        alert("Loaded " + node.title);
      }
    });
    return node_page_view(11);
  }
  catch (error) { console.log('mymodule_sample_page - ' + error); }
}

However, when I attempt to test this in my module, I get the alert "Loaded your node" but the content is not actually displayed on the page by node_page_view(). What do I need to do to display the content?

2 Answers 2

2

In mymodule_sample_page() just return an empty div container, for example:

<div id="my_node_11"></div>

Then attach a pageshow handler to your page via hook_menu(), then in the pageshow handler call node_load(), and in its success inject the content into your empty div container.

The page_callback can not have any async calls in it, as all async calls have to be handled after the page is actually shown.

FYI, DrupalGap has built in support to view nodes, just navigate to node/11 in the app. Here's a brief example demonstrating pageshow: http://www.drupalgap.org/node/154

0

Thanks to Tyler. I put the answer with more detail and proven by my successful experiment. Hope this can do some helps.

function mymodule_sample_page() {
  var display_page = '<div id="my_node_11"></div>'; 

  return display_page;
}

function mymodule_sample_pageshow() {
  try{
        var nid = 11;
        node_load(nid, {
        success:function(node){

         var content = node.content;

         $('#' + 'my_node_' + nid).html(content).trigger('create');
          }
        });
   }
  catch (error) { console.log('mymodule_sample_page - ' + error); }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.