How do i fully specify a view in the Collection.Nodeview? returned json nid is invalid.

Created on 21 January 2016, almost 9 years ago
Updated 14 December 2023, about 1 year ago

I have created an article view that contains different displays and I am following the simplified instructions on the module home page to get the view.

var viewCollection = new Drupal.Backbone.Collections.NodeView();
viewCollection.viewName = 'articles';
viewCollection.fetch({
    success: function (jsonView) {
        var result = $("#backbone-view-container");
        result.html(JSON.stringify(jsonView));
    }
});

this is returning the following array of objects with an invalid node id.

[
  {
    "node":{
      "node_title":"my node title",
      "nid":"\"\""
   }
  }
]

i was not expecting a meaningful result using the above js because i havent defined a display_id to fully qualify my view. i.e. the viewname articles can refer to one or more actual views... this is best illustrated comparing the API to the core Drupal API for embedding a view

views_embed_view($name, $display_id = 'default')

I was kind of expecting to need to define a Service View (to return the json i want) and then specify it through the API to get the exact data I want.

Please can you advise further on the correct way of setting up backbone to use with views.

Thanks

Laurence

πŸ› Bug report
Status

Closed: duplicate

Version

1.0

Component

JS Code

Created by

πŸ‡¬πŸ‡§United Kingdom Syntapse

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024