napp.alloy.adapter.restapi icon indicating copy to clipboard operation
napp.alloy.adapter.restapi copied to clipboard

App crashes on fetch

Open dottodot opened this issue 12 years ago • 5 comments

Not too sure is this issue is for here but thought I'd start her anyway.

When my app launches it immediately crashes and closes with no error.

Model

exports.definition = {  
    config: {
        "URL": "http://www.example.com/api/events",
        "debug": 1, 
        "adapter": {
            "type": "restapi",
            "collection_name": "plugevents",
            "idAttribute": "nid"
        },
    },      
    extendModel: function(Model) {      
        _.extend(Model.prototype, {});
        return Model;
    },  
    extendCollection: function(Collection) {        
        _.extend(Collection.prototype, {});
        return Collection;
    }       
};

Fetch Collection

var collection = Alloy.createCollection("plugevents"); //or model
collection.fetch({ 
    success : function(){  
         Ti.API.info(collection.models);    
        _.each(collection.models, function(element, index, list){

        });
    },
    error : function(){
        Ti.API.error("hmm - this is not good!");
    }
});

If I remove

Ti.API.info(collection.models); 
``
the app doesn't crash.

dottodot avatar Oct 21 '13 08:10 dottodot

I'm having the same issue. App crashes on fetch when I do...

_.each(collection.models, function(element, index, list){
    Ti.API.info(element);
});

I'm just trying to figure out how to access my data in 'element'.

If I remove the Ti.API.info, the app does not crash.

chiefupstart avatar Oct 25 '13 16:10 chiefupstart

What about: Ti.API.info(JSON.stringify(element)); ?

nuno avatar Oct 25 '13 16:10 nuno

Ti.API.info(JSON.stringify(element)); will not crash the app and I can see my data.

What's odd is that I can get element.id (the id generated by restapi.js) but I cannot access any other data in my JSON. element.LibraryCategoriesTitle, for example, just returns .

chiefupstart avatar Oct 25 '13 17:10 chiefupstart

Ah, I figured it out by reading https://developer.appcelerator.com/question/153642/empty-collection-after-fetch.

It's element.attributes['LibraryCategoriesTitle'].

Sheesh!

chiefupstart avatar Oct 26 '13 04:10 chiefupstart

Thanks, it was due to not using JSON.stringify

dottodot avatar Oct 26 '13 14:10 dottodot