1

I am experimenting around with integrating Ember.Data into my application and also wanted to find out how to propery use ArrayController. Unfortunately I didn't even get around simple databinding on the controller.

I simply can't figure out where I went wrong, so I fully expect someone to be able to point out: Hey you wrote .extend instead of .create

I am trying something rather similar to what Discouse is doing in their AdminSiteSettings:

The controller in question:

App.UsersController = Ember.ArrayController.extend({
    foo: 'bar'
});

route:

App.UsersRoute = Ember.Route.extend({
    model: function () {
        var users = App.User.find();
        return users;
    },
    setupController: function (controller, model) {
        controller.set('model', model);
        console.log(controller.get('foo'));  // this works correctly => bar
    }
});

Only problem: The template is being rendered, but I can't bind to the foo property:

<script type="text/x-handlebars" data-template=name="users">
    We render the correct template
    {{foo}}
</script>

Only problem is: The Template never renders 'bar'. It's just empty.

Now I found something similar in Discourse where they have a textbox bound to filter: https://github.com/discourse/discourse/blob/master/app/assets/javascripts/admin/controllers/admin_site_settings_controller.js

I can't really understand why my controller property is not showing up, (and yes I am actually trying to get Ember.data to work, but since this can easily be reproduced without it I figured I'd settle for the simple foo: bar property :(

Versions in use:

  • Ember.js: v1.0.0-rc.4-23-gbfd3023
  • Handlebars: 1.0.0-rc.4
  • Ember.data: 13

Any pointers are welcome. Thanks!

4
  • 1
    You have a typo in the template script tag, it should be data-template-name. Does it render the text part of the template? Putting up the example on jsbin, would help with debugging. Commented Jun 29, 2013 at 13:23
  • Yes it actually renders the text, but maybe that's due to some quirk in the Chrome renderer .. I'll fix that and try to put it into jsbin. Commented Jun 29, 2013 at 17:31
  • Believe it or not the typo was causing this. Somehow Chrome managed to render the text in the template to the screen, but the Ember bindings obviously failed. Could you add it as an answer so I can accept it? Commented Jun 29, 2013 at 22:47
  • Hah!, glad you got it fixed. I have also had my share of create vs extend moments. The best one though was a Route extending a Controller. :) Commented Jun 30, 2013 at 3:27

1 Answer 1

2

I don't know exactly where you app fails, but I have tried to recreate your use case and in this example jsbin it's working correctly, have a look.

Hope it helps.

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

1 Comment

Thanks for your help and effort! Darshan was onto something, for some strange reason the typo in the Markup made the text in the template appear on screen, but the bindings did fail.. Well I was pretty sure it was something insanely stupid and simple that made me stumble :)

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.