0

I have two lists that contain the same Elements as well as different elements. How to make a list from these two lists and spring me commonalities and new items?

...
            <list-of-items items="application.units"
                           label="$item.name"
                           selected-item="unit"
                           selectable="true"
                           onedit="on_edit_unit($item)"
                           editable="false"
                           size="small">
            </list-of-items>
            <list-of-items items="applicationCible.units"
                           label="$item.name"
                           selected-item="unit"
                           selectable="true"
                           onedit="on_edit_unit($item)"
                           editable="false"
                           size="small">
            </list-of-items>
...

Update

In my HTML:

..
          <list-of-items items="platforms.concat(platformsCible).unique()"
                           label="$item"
                           selected-item="platform"
                           createfunction="add_platform($name)"
                           selectable="true"
                           editable="false"
                           size="small">
            </list-of-items>
..

In my JS:

propertiesModule.controller('PropertiesCtrl', ['$scope', '$routeParams', 'PropertiesService', 'ApplicationService', 'PlatformService', 'Page',  function ($scope, $routeParams, PropertiesService, ApplicationService, PlatformService, Page) {

...

Array.prototype.unique = function() {
    var a = this.concat();
    for(var i=0; i<a.length; ++i) {
        for(var j=i+1; j<a.length; ++j) {
            if(a[i] === a[j])
                a.splice(j--, 1);
        }
    }

    return a;
};

}]);

There is duplicate item with this method

halfer
  • 19,824
  • 17
  • 99
  • 186
Mercer
  • 9,736
  • 30
  • 105
  • 170

1 Answers1

1

One way to do this is to concatenate the two lists using Array.prototype.concat():

<list-of-items items="application.units.concat(applicationCible.units)"
               label="$item.name"
               selected-item="unit"
               selectable="true"
               onedit="on_edit_unit($item)"
               editable="false"
               size="small">
</list-of-items>
Catalin MUNTEANU
  • 5,618
  • 2
  • 35
  • 43