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 8049839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:53:51+00:00 2026-06-05T06:53:51+00:00

I have created a custom component which will contain reference to view(bound to a

  • 0

I have created a custom component which will contain reference to view(bound to a handlebar template). And my template has a button which I want to attach a click handler to it.

I will create the instance of my component dynamically and attach it to different divs. But my problem is how I can hook the view to the event handler which is defined in corresponding component instance.

    App.ImageView = Ember.View.extend({
        "templateName" : "image-template",
        "imagePath" : null,
        "controller" : null
    });

    App.ImageSwitcher = Ember.Object.extend({
        renderTo : null,
        init: function(){
            this.set("view",App.ImageView.create());
        }
        renderOnScreen: function(){
            this.get("view").appendTo(renderTo);
        }
        clickHandler : function(evt){
        }
    })

<script type="text/x-handlebars" data-template-name="image-template">
    <img {{bindAttr src="imagePath"}} />
    <input type="button" value="Change image" />
</script>

Component instance creation:

var component = App.ImageSwitcher.create({renderTo:"#div"});
component.renderOnScreen()


var component1 = App.ImageSwitcher.create({renderTo:"#div1"});
component1.renderOnScreen()

Now I want the buttons to invoke the clickHandler defined in corresponding App.ImageSwitcher instance. Is there any way to it. I tried to have a reference to the App.ImageSwitcher instance within the view. But it is not a clean way of doing it.

  • 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-05T06:53:52+00:00Added an answer on June 5, 2026 at 6:53 am

    You can mixin Ember.TargetActionSupport into your view, and then have a click handler on that, as such:

    App.ImageView = Ember.View.extend(Ember.TargetActionSupport, {
        templateName: "image-template",
        action: "clickHandler",
        imagePath: null,
        controller: null,
        click: function() {
             this.triggerAction();
        }
    });
    
    App.ImageSwitcher = Ember.Object.extend({
        renderTo : null,
        init: function(){
            this.set("view",App.ImageView.create({target: this));
        }
        renderOnScreen: function(){
            this.get("view").appendTo(renderTo);
        }
        clickHandler : function(evt){
        }
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created custom posts and I want one page in my site to
I have created custom cell in which there are n number of image views.
I have created one custom list view item for my application. Suppose for any
I have created a custom CreateUser in Asp.Net Membership. Now what i want is
I am writing a custom component (derived from a relative layout) which has to
I have jsf application in which I have to use a facelet custom component
I have created custom component for displaying text with either Simple or Password mode,
I have a custom component called shopView which is an MXML skinnable component. I
I have created a non-visual component in C# which is designed as a placeholder
I have created custom component and a route plugin for Joomla 1.5 to to

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.