0
votes

Hi and thanks for taking the time to answer my question.

I have recently started using Ember and I've gotten familiar with the basic workflow of the framework (routes, controllers, models, data-templates, etc.). However, the need has arisen for much more complex screens and much more complex javascript logic.

I am proficient in javascript/jquery and could easily do the following in a couple of javascript functions. However, I am trying to avoid going that route and instead do it the proper, ember way.

I have a list of items (item0, ..., item 9). There is a + (add new item button).

I need the following behaviour:

When a user clicks the add new item button i want to add a new <li> elemenet which will contain:

a select element, a textbox, and a remove button (which when clicked removes the <li> element and everything inside.

Now when the user clicks the + button again, I want to add a new <li> element with the same elements within it, however this time, the item which was selected in the previous <li> should not be featured.

When a user clicks a remove button (there will be as many as there as <li> elements), I want to be able to recalculate the list of available.

Also, what is really important for me is, how can I get a reference to the button (remove project) which was clicked? In pure javascript you send a which is an object representing the clicked element. How do I do that in ember?

Since I do not know where to start, I haven't written any code and thus I won't ask you to come up with a fiddle example. I'd like to ask you for directions on which ember concepts I should read up on to get familiarised with dynamically adding and removing elements (in my case an element consists of a select element, textbox and a remove button).

Thank you so much!

1

1 Answers

0
votes

Ok so for anyone who was interested in the answer. I am using Component, which I then dynamically inject in a View. The action for the + (add new item) button is handled in the controller responsible for the main page. Regarding the remove action, using this.remove(); will simply remove the whole template which contains the buttons which was clicked. All of this piping is done by ember.