luckylooke / dragular

Angular drag and drop based on dragula.js. Visit
http://luckylooke.github.io/dragular/
MIT License
209 stars 67 forks source link

How can I drop element from one container to another container's nested array Object? #142

Closed AkbarAlam closed 7 years ago

AkbarAlam commented 7 years ago

How can I drop element from one container to anothre container's nested array Object?This is one container item

 $scope.items1 = [
        {
            'name' : 'x',
            'age' : '4'
        },
        {
            'name' : 'y',
            'age' : '5'
        },
       {
            'name' : 'z',
            'age' : '6'
        }
     ];

i want to drop each element in a new container it should be

$scope.items2 = [

        {
            'key' : 'info',
            'value' : [ {
            'name' : 'x',
            'age' : '4'
        }]
        },
        {
            'key' : 'info',
            'value' : [ {
            'name' : 'y',
            'age' : '5'
        }]
        },
        {
            'key' : 'info',
            'value' :[ {
            'name' : 'y',
            'age' : '5'
        }]
        },

     ];

how should i write my dragularService

luckylooke commented 7 years ago

Hi Akbar, thanks for using it, I am glad you like it, currently I am working on total rewrite of library, it will be much easier to use/maintain etc...

To your problem.

I need to know exact rules you want achieve.. for example if item from items1 can be dropped between item2 or only inside items2 into values array? Etc..

Please write me all use cases you want to support in your example.

AkbarAlam commented 7 years ago

Hey, Item1 can be dropped only inside item2 value array.So the value array is empty initially. Once the item1 is dropped it should go inside the value array. here I am struggling

luckylooke commented 7 years ago

I am sorry I am busy now.. too much deadlines.. :/ Preparing code in jsfiddle, codepen.. or similar is much faster for me to solve problems.. but dont worry, I will answer you soon. It is possible and not so difficult as it looks at the first glance.

luckylooke commented 7 years ago

Here is codepen of your case: https://codepen.io/luckylooke/pen/LyoWzR

AkbarAlam commented 7 years ago

Thanks but there is a small issue. the value of item 2 should be empty initially.

{
  key:'info',
  value: [ ]
}

once the data from item 1 is dropped in item 2 it will go directly in the value. then it should look like

$scope.items2 = [

        {
            'key' : 'info',
            'value' : [ {
            'name' : 'x',
            'age' : '4'
        }]
        },
        {
            'key' : 'info',
            'value' : [ {
            'name' : 'y',
            'age' : '5'
        }]
        },
        {
            'key' : 'info',
            'value' :[ {
            'name' : 'y',
            'age' : '5'
        }]
        },

     ];
luckylooke commented 7 years ago

Oh, I am sorry, I was in a hurry and I made some mistakes.. now fixed in same codepen. Check it please, if it is OK than please accept also answer on stackoverflow, thanks ;)

AkbarAlam commented 7 years ago

Thank you so much. just a question if I want to do it with a model how should I write the service?

luckylooke commented 7 years ago

Synced with models: https://codepen.io/luckylooke/pen/KmLGbM

AkbarAlam commented 7 years ago

Thank you so much :)