0

I have this simple JSON feed which I am attempting to read in a BackBone.JS app.

My challenge is the network traffic comes up completely blank as illustrated below:

enter image description here Using the following code:

 //Collections
  var Topics = Backbone.Collection.extend({
      model: TopicStruct,

      initialize: function(){
          console.log('Collector Responding!');
      },

      url: 'http://dev-sw-budget.gotpantheon.com/sort-coordinator-json',

      render: function(){
          console.log('Topics Render Responding!');
      },

  });

Why am I not getting my data in my Backbone app?

UPDATE:

My fetching code:

$(document).ready(
      function(){
          console.log('--- DOM Ready!');
          var topics = new Topics();
          var topicsView = new TopicsList({collection: topics});
          topics.fetch({reset: true});

          $('#data table').append(topicsView.el);
      }
  );
halfer
  • 19,824
  • 17
  • 99
  • 186
sisko
  • 9,604
  • 20
  • 67
  • 139

1 Answers1

1

I think the problem it's that you are not calling fetch() in your collection. I have put your code together in a JSFiddle and it works.

var topics = new Topics();
topics.fetch();
Puigcerber
  • 9,814
  • 6
  • 40
  • 51
  • Thanks for you input but I was calling fetch. I have included a code fragment in an update to my question. I've tried a number of JSON feeds but fields continue to be ignored and not fetched by the browser – sisko Apr 09 '14 at 09:50
  • Have you checked the example in the JsFiddle? If you open the console you can see it working. – Puigcerber Apr 09 '14 at 10:24
  • Thanks again. I have looked at the JSFiddle and you are right - it does work. However, the network traffic shows one field out of two is begin fetched. The JSON feed contains NID and AUTHOR fields. Only the NID is being fetched by the browser – sisko Apr 09 '14 at 10:44
  • Are you sure? Because http://dev-sw-budget.gotpantheon.com/sort-coordinator-json has just the `nid`field. – Puigcerber Apr 09 '14 at 12:30
  • Yep! Perhaps your browser is showing you a cached version. The link you provided shows two fields per json object – sisko Apr 09 '14 at 13:15
  • What do you mean? If I go to http://dev-sw-budget.gotpantheon.com/sort-coordinator-json that it's the link that appears in your code, it loads an array with 17 objects whose only field is nid. – Puigcerber Apr 09 '14 at 14:54
  • Checkout the update I just included in you answer above – sisko Apr 09 '14 at 15:12
  • Weird, I just see the `nid` fields, but anyway, if Backbone it's able to fetch the collection both fields should be inside of the models. – Puigcerber Apr 09 '14 at 15:59
  • I agree but that is the nature of the problem I'm facing. The network data shows lots of JSON fields have been dropes – sisko Apr 09 '14 at 19:46
  • Don't you think then that the problem is in your backend? Whoever is serving that `sort-coordinator-json` is failing to serve all the data. – Puigcerber Apr 10 '14 at 08:01
  • No, I'm serving the JSON from a different Drupal based site. I'm using Views to generate the JSON. I'm just surprised we seem to be seeing different data. Regardless, I have two separate Views generating JSON from the same site and my BackBone.js app still doesn't see all the fields. – sisko Apr 10 '14 at 08:22
  • Thanks for your continued help. I just created a link within my Backbone app which points to sort-coordinator-json. Just as you are experiencing, I'm seeing single field data instead of two. I literally have two chrome windows open side-by-side pointing at the same address but the page loaded from the backbone app shows only NID data while the page I load directly shows both NID & AUTHOR ??? – sisko Apr 10 '14 at 08:55
  • Weirdest thing ever. May be you experiencing cache problems? – Puigcerber Apr 10 '14 at 09:28
  • 1
    I feel like an idiot. The problem is PERMISSIONS! The window where I go directly to the JSON feed shows all the fields because I am logged in. The link from the Backbone app shows just the NID because there is a permission set to disallow anonymous users to view the value of AUTHOR. I am really sorry for wasting your time. – sisko Apr 10 '14 at 11:08