Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

What I'm trying to do is when the page is loaded it will show the user a list of all their "contacts". There is a fair bit of code so I put it all HERE and below is just the load method.

$(window).load(function () {
        var Contacts = StackMob.Model.extend({ schemaName: 'contacts' });
        var myContacts = new Contacts();
        var q = new StackMob.Collection.Query();
        q.orderAsc('firstname'); //sort by firstname in ascending order
        myContacts.query(q, {
            success: function (model) {
                console.log(model.toJSON());

                for (var i = 0; i < model.length; i++) {
                    var data = ({
                        FirstName: model[i].attributes.firstname,
                        LastName: model[i].attributes.lastname,
                        Pno: model[i].attributes.phoneno,
                        Emails: model[i].attributes.email,
                        objIdel: model[i].contacts_id,
                        objIdeit: model[i].contacts_id
                    });
                    var template = Handlebars.compile($('#template').html());

                    var html = template(results);

                    $("#contacts").append(template(data));
                }
            },
            error: function (model, response) {
                console.debug(response);
            }
        });
    });

console.log(model.toJSON()); shows what I would expect but It doesn't seem to be getting into the for loop at all.

share|improve this question

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.