1

I have an Ember JS drag & drop view which is used to connect items to a bigger piece. As the construct grows it overlaps the viewport vertically.

What I want to do now is to have a small preview-view of the d&d view.

I want the controller data from the first (big, vertically overlapping ) view that I interact with, to appear in a second view (preview, small, not vertically overlapping ).

Any Idea's how to render a view twice with data from one view, OR connect a view to another view's controller?

thanks in advance!

1 Answers1

0

First of all, you should not be using views anymore. Use components.

Then, move all logic and state into a model. Have a model that represents your drag-n-drop gizmo, and feed into two components: one component for a preview interface, the other one for the full interface.

Andrey Mikhaylov - lolmaus
  • 23,107
  • 6
  • 84
  • 133
  • Why are you "adding child views programmatically" in the first place? Also, my suggestion to move the logic and state into a model applies to views too. – Andrey Mikhaylov - lolmaus Jun 10 '15 at 16:50
  • Thanks for your answer. I know about the fact that components would be better. Anyway the code was written with views because it was the only way i knew to handle adding child views programaticaly. I use ember-data and a rails api, can i use both, the ds.model and a local model in the same time, i was not planing to make a request everytime a part is moved?! – Chris_ÆVIATOR.CC Jun 10 '15 at 16:51
  • I meant "model" in a concept sense, it shouldn't necessarily be a `DS.Model`, it can be a mere object. But `DS.Model` is also fine, just don't call `.save()` on it. – Andrey Mikhaylov - lolmaus Jun 10 '15 at 16:52
  • every time an element is dropped, it catches all the item data from the api, and creates a child view (there are different item-categories with different templates) which represents the item. Every item is stored in an array in the controller , the controller also checks if it possible to drop the part on the position – Chris_ÆVIATOR.CC Jun 10 '15 at 16:58
  • so the solution would be to just move the array of items to the model instead of the controller and then create another view which displays the model data ? – Chris_ÆVIATOR.CC Jun 10 '15 at 17:02
  • Yes. I also believe that you might not need to programmatically initialize views. Just use `{{#if}}` and `{{#each}}` to render required views/components where necessary. – Andrey Mikhaylov - lolmaus Jun 10 '15 at 17:06
  • Thanks for your answer so far. I am still stuck with implementation. An important part of the app is that I can exchange items and that i have control of WHERE the item is placed. For that i am using this.insertAt alot ,is there any compareable function i can use with the store? – Chris_ÆVIATOR.CC Jun 15 '15 at 12:04