Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8849769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:44:21+00:00 2026-06-14T12:44:21+00:00

I added the example application. http://jsfiddle.net/Sly7/amG56/ Js: App = Ember.Application.create(); App.ApplicationController = Ember.ArrayController.extend({ selectedBook:

  • 0

I added the example application.
http://jsfiddle.net/Sly7/amG56/

Js:

App = Ember.Application.create();

App.ApplicationController = Ember.ArrayController.extend({
  selectedBook: null
});

App.ApplicationView = Ember.View.extend({

  actions: {
    selectBook: function(book) {
      this.get('controller').set("selectedBook", book);
    },

    cancel: function(book) {
      alert(book);
    }
  }
});

App.Book = Em.Object.extend({
  name: null
});

Template:

<script type="text/x-handlebars">
  {{#each book in books}}
    <a {{action "selectBook" book target="view"}} href="#">select {{book.name}}</a><br />
  {{/each}}
  <hr />
  Selected Book: {{selectedBook.name}}
  <br />
  <a {{action "cancel" selectedBook target="view"}} href="#">cancel selected book</a>
</script>

​

Select one of the books. You will see that name of the book will be displayed. But the “cancel selected book” link does not work.

I think the problem is context of the action helper does not change when a book is selected.

How do I implement an action helper which has a changing context? Or is it a bug?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:44:22+00:00Added an answer on June 14, 2026 at 12:44 pm

    The answer is in the guides
    http://emberjs.com/guides/templates/actions/#toc_action-parameters

    And the context is lazily evaluated, so the problem does not occur anymore

    DEPRECATED ANSWER BELOW

    The problem here is that the action helper is interpreted with the selectedBook context. But at this time, selectedBook is null. So when clicking on the link, even if you previously select a book, it’s too late, for the registered action, the context is still null.
    As a workaround, you can enclose this with a {{with}} block.

    {{#with selectedBook}} 
      Selected Book: {{name}}
      <br />
      <a {{action cancel this target="view"}} href="#">cancel selected   book</a>
    {{/with}}
    

    see: http://jsfiddle.net/x82dr/17/

    BTW, you can see the code of the ApplicationView, where I access the application controller, using the controller property. With Ember.js convention, the controller is injected to the view when the application initialize

    UPDATE: The use of the {{with}} helper seems to be not mandatory now, see: https://github.com/emberjs/ember.js/issues/1150

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update : Added simple test example http://jsfiddle.net/7UhrW/1/ using normalize.css. Chrome/WebKit and Firefox have different
I added CakeDC-Users plugin in app/plugins. Now for http://example.com/ , if i click the
I make Android application which must receive data from the page http://example.com/get.php?id=1 . For
When I try to initialize my ember App with an ArrayController I got an
I am creating the application using the following tutorial http://www.coderzheaven.com/2011/05/09/android-tabbars-example/ For every tab i
I added php_value session.cookie_domain .example.com to my .htaccess in order to be able to
I have added a ColorPropertyDescriptor to the Shapes example in GEF, however this displays
I found one example in which buttons are added to panels (instances of JPanel
QUESTION ONE: In the following example, ive added a listener to the foundMic. My
I'm working on a webpage (let's call it example.com) and added the DNS record

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.