Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App crashes on fetch #21

Open
dottodot opened this issue Oct 21, 2013 · 5 comments
Open

App crashes on fetch #21

dottodot opened this issue Oct 21, 2013 · 5 comments

Comments

@dottodot
Copy link

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.
@chiefupstart
Copy link

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.

@nuno
Copy link

nuno commented Oct 25, 2013

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

@chiefupstart
Copy link

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
Copy link

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

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

Sheesh!

@dottodot
Copy link
Author

Thanks, it was due to not using JSON.stringify

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants