0

I'm fairly new to Drupal and Drupalgap.

My Drupal site has a view/content called "donations".

In admin/structure/views, there are two PATHs: /current-donations and /available-donations. And of course, this URL works fine: http://127.0.0.1:8083/current-donations

Now I'd like to render this view in drupalgap using a views render array.

My first attempt looked like:

function mobile_donor_donations_page() {
try {
    console.log('mobile_donor_donations_list_page()-e');
    var content = {};
    content['avail_donations_list'] = {
        theme: 'view',
        format: 'ul',
        path: '/available-donations', /* the path to the view in Drupal */
        row_callback: 'mobile_donor_donations_list_row',
        empty_callback: 'mobile_donor_donations_list_empty',
        attributes: {
            id: 'avail_donations_list_view'
        }
    };
    return content;
}
catch (error) { console.log(':ER:mobile_donor_donations_page: ' + error); };
}

The above function gets called fine -- on my console (chrome, Ripple) I see

GET: http://127.0.0.1:8083/?q=/available-donations&page=0
200 - OK
views_embed_view - success - TypeError: Cannot read    property 'count' of undefined

Looking at the views_embed_view() code below, it is throwing an exception because results.view is undefined:

// Render the view if there are some results, or if there are no results and an
// empty_callback has been specified. Otherwise remove the empty div container for
// the view from the DOM.
if (results.view.count != 0 || results.view.count == 0 && options.empty_callback) {

I tried http://127.0.0.1:8083/?q=/available-donations&page=0 from my browser, it returns html, not JSON.

To force JSON returned, I tried

path: 'drupalgap/node.json&parameters[type]=donation', /* the path to the view in Drupal */

This PATH does indeed return my content as JSON, however the error remains, since the JSON doesn't contain a "view" element.

GET: http://127.0.0.1:8083/?q=drupalgap/node.json&parameters[type]=donation&page=0
200 - OK
views_embed_view - success - TypeError: Cannot read property 'count' of undefined

What PATH do I need to supply, or do I need to change structure of my content in Drupal to get the view to render?

Thanks!

3
  • Did you create a JSON Data Document display in your View, then give it a page path? That is the path that you use when building the Views Render Array. Commented Dec 12, 2016 at 16:20
  • No, I was using the original view for the Drupal site. I followed your instructions below and created a new view with format "JSON data document" with path 127.0.0.1:8083/my-donations.json. This works great and I see the "count" element which was missing before. tylerfrankenstein.com/code/… Commented Dec 13, 2016 at 3:06
  • Great, I'm glad it is working. Please accept the answer when you have a moment, thank you. Commented Dec 13, 2016 at 14:38

1 Answer 1

0

Be sure to create a JSON Data Document display for your View with a unique page path, then you can use that path in your DrupalGap Views Render Array. More documentation and examples are available here: http://docs.drupalgap.org/7/Views/Displaying_a_View/Views_Render_Array

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.