Note that there are some explanatory texts on larger screens.

plurals
  1. POBackbone cannot call method 'toJSON' of undefined / not loading data
    primarykey
    data
    text
    <p>I'm trying to fetch some data and display it with Backbone, but having no luck - I am not getting any errors, just no rendering (I built this really simple app using the todos example as a guide)</p> <p>index.html:</p> <pre><code>&lt;!doctype html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Hello Backbone&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="sps-container"&gt; &lt;div id="main"&gt; &lt;ul id="service-providers"&gt;&lt;/ul&gt; &lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.0/backbone-min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="/app.js"&gt;&lt;/script&gt; &lt;!-- Templates --&gt; &lt;script type="text/template" id="sp-template"&gt; &lt;div class="view"&gt; &lt;label&gt;&lt;%- name %&gt;&lt;/label&gt; &lt;/div&gt; &lt;/script&gt; &lt;/html&gt; </code></pre> <p>app.js</p> <pre><code>$(function(){ var ServiceProvider = Backbone.Model.extend({ defaults : function() { return { id : "", version : 1, name : "" }; } }); var ServiceProviderList = Backbone.Collection.extend({ url: '/web-admin/faces/Backbone/data.json', model : ServiceProvider }); var myCollection = new ServiceProviderList(); var ServiceProviderView = Backbone.View.extend({ el : $("#service-providers"), tagName : "li", initialize : function() { _.bindAll(this, 'render'); this.template = _.template($('#sp-template').html()); this.render(); }, render : function() { this.$el.html(this.template(this.model.toJSON())); return this; } }); myCollection.fetch(function(c) { var v = new ServiceProviderView(c); main.html(v.render().el); }); var SPView = new ServiceProviderView(); }); </code></pre> <p>data.json</p> <pre><code>[ { "id": "03c88b31-6719-4662-9ad8-64f247de13f0", "version": 1, "name": "Dino Tel" }, { "id": "936690b4-6a4a-436d-abed-8ca316fbae22", "version": 1, "name": "Krusty Tel" } ] </code></pre> <p>I think it's not loading any data - there are no other errors though, and the json file is available. Am I missing something?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload