1

I have this Ajax and Ember.js call

$.ajax({
    url: '../data',
    type: 'GET',
    cache: false,
    dataType: 'json',
    data: ({
        func: "getAllLists"
    }),
    success: function(data) {
        console.log('DEBUG: GET Data OK');
        var list = [
            {
                uid: data[0].uid
            }
        ];
        App.ListRoute = Ember.Route.extend({
            model: function () {
                return list;
            }
        });
    },
    error: function() {
        console.log('DEBUG: GET Data Failed');
    }
});

this is tam

{{#each}}
<li>
    {{#link-to 'project' this}}
        {{title}}
    {{/link-to}}
</li>
{{/each}}

and i have an error: Assertion Failed: The value that #each loops over must be an Array. You passed (generated list controller). What im doing wrong?

1 Answer 1

1

You need to do your $.ajax() call inside the App.ListRoute, not the other way around:

App.ListRoute = Ember.Route.extend({
    model: function () {
        list = $.ajax({
            url: '../data',
            type: 'GET',
            cache: false,
            dataType: 'json',
            data: ({
                func: "getAllLists"
            }),
        }).then( function(data) {
            console.log('DEBUG: GET Data OK');
            var list = [{
                uid: data[0].uid
            }];
        },);
        return list;
    }
});

Note that Ember will not enter the route until the ajax call is complete (because it will wait for the then() to resolve. Have a look at http://emberjs.com/guides/routing/asynchronous-routing/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.