1

I am working in SharePoint 2013 Foundation and I have a custom list named Properties that I am trying to use in a Backbone Application. The list contains all 90 of our properties and each property's corresponding Property Number. I am just trying in this first step to return the list's contents to the page.

I have included jquery-1.9.0.js, json2.js, underscore-1.4.3.js, backbone-0.9.10.js, backbone-sharepoint.odata.js and home.js in the head of my page (Home.aspx).

Here is the contents of home.js:

var Property = Backbone.SP.Item.extend({});

var Properties = Backbone.SP.List.extend({
    model: Property,
    site: '/',
    list: 'Properties',
    view: ''
});

var PropertiesView = Backbone.View.extend({
    tagName: "ul",
    tpl: _.template(
        "<% _.each(properties, function(property){ %>" + 
            "<li><%= property.PropNumber + ' -- ' + property.Title %></li>" + 
        "<% }); %>"
    ),
    render: function(){
        $(this.el).html( this.tpl( { properties: this.collection.toJSON() } ) );
        $('#addressbooks').append( this.el );
    }
});

jQuery(document).ready(function($) {

    var properties = new Properties();
    var view = new PropertiesView({ collection: properties });
    properties.bind("reset", view.render, view);
    properties.fetch();

});

Nothing is getting appended to the page and when I debug through Developer Tools, I get an error of "Resource not found for the segment 'undefined'." Since this is the ONLY documentation for using the SharePoint.Backbone plugin (https://github.com/lstak/Backbone.SharePoint), I am hoping that the community can help me see what I am doing wrong.

Thanks in Advance!

-----UPDATE----- The list is apparently OK. I ran this REST code and all of the properties appeared. The problem is I don't know how to turn this into a Backbone Collection without using Istak's library (which is the thing not working):

jQuery(document).ready(function($) {
//$('#addressbooks')
    $.ajax({
        url: "http://edrdbdev/_api/web/lists/GetByTitle('Properties')/items",
        type: "GET",
        headers: { "accept" : "application/json;odata=verbose" },
        success: function(data){
            $.each(data.d.results, function(index, item){
                $('#addressbooks').append( "<li><p>" + item.PropNumber + " -- " + item.Title + "</p></li>"  );
            });
        },
        error: function(error){
            alert(JSON.stringify(error));
        }
    });
});
5
  • Is var properties = new Properties; correct? Should it not be var properties = new Properties();? Feb 5 '14 at 21:25
  • The documentation had it as a Property and not a Method but I think it should be as you say. I made the change (and edited my question) but still get the same error and no content.
    – jgravois
    Feb 5 '14 at 21:34
  • BTW, since this project is using ListData you should know there is a bug with task approval: sharepoint.stackexchange.com/questions/64273/… Feb 5 '14 at 22:50
  • I can give you some jQuery functions that I use with ListData, but you should probably post on StackExchange regarding the BackBone question. Feb 5 '14 at 22:53
  • I would live to see your functions
    – jgravois
    Feb 5 '14 at 22:56
0

Usually I encounter this error when my JavaScript code is trying to access a list whose name is in a variable that is being used for the title/URL of the list but is in fact undefined. So looking in developer tools, you should be able to see on the network tab if you are attempting to access a URL or make a call to http://servername/_api/web/lists/getbytitle('udefined'). I suspect something is wrong with your Properties model.You'll need to investigate more with developer tools.

3
  • 1
    The Request URL is "edrdbdev/_vti_bin/ListData.svc/undefined" -- not good. I made sure that I copied the same Properties model accurately (substituting my list name for the example) so what I am doing now is creating a "Contacts" list and will use the actual code from the example to see if that works. Thanks for helping!
    – jgravois
    Feb 5 '14 at 22:05
  • I suspected from the error this was ListData.svc. I am sad to say I've seen that message enough I am surprised it's not in my nightmares yet! Feb 5 '14 at 22:15
  • I added the list (Contacts) and ran the EXACT code found in the documentation and received the same error. I was able to access the list via REST (I added my example to my question) but I need the JSON to be a collection in BackBone to feed our BackBone application.
    – jgravois
    Feb 5 '14 at 22:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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