我将在一个页面中选择图像,并在其他页面中显示所选择的5个图像。在向服务器发送put请求之前,所选图像最初将存储在选择阵列中。在显示页面时,我有一个名为更改图片的按钮,我在选择图像页面中选择5个图像后向服务器发送放置请求,将存储在名为 other_media 的数组中。如果我点击更改图片按钮它将重定向到选择图像页面(再次选中的数组将为空)在选择图像页面时,那些已经选择显示在右侧的图像[意味着我需要将other_media数组中的数据推送到选定的数组]在plunker中的结果。我需要准确地显示已经选择(张贴或放置)的图像。只有一页我选择了图像。 Plunker https://plnkr.co/edit/BM4AavLn9uKxKL4wdbT6?p=preview
<div class="row">
<div class="col-xs-6 col-sm-5 col-md-5">
<h3 style="text-align: center;text-shadow: 0px 4px 6px;">All Pictures</h3>
<div class="row" ng-repeat="media in pinMedia">
<!-- pin.media_id!=media._id || -->
<div class="col-xs-12 col-sm-12 col-md-5">
<img ng-src="http://placehold.it/{{images}}" width="200px" />
<p>{{media.Name}}</p>
<div class="col-xs-12 col-sm-12 col-md-5">
<button ng-disabled='limit()' class="btn btn-success" style="border: .0625rem solid transparent;padding: .465rem 1rem;" ng-click="toselected(media)">
<i class="fa fa-picture-o"></i>
Set Picture</button >
</div>
</div>
</div>
</div>
<div class="col-xs-6 col-sm-5 col-md-5">
<h3 style="text-align: center;text-shadow: 0px 4px 6px;">Selected Pictures</h3>
<div ng-repeat="media in selected">
<!-- pin.media_id==media._id && -->
<div>
<img ng-src="http://placehold.it/{{images}}" width="200px" />
<p>{{media.Name}}</p>
<div>
<a class="btn btn-success " style="border: .0625rem solid transparent;padding: .465rem 1rem;" ng-click="tosource(media)">
<i class="fa fa-picture-o"></i>
Remove Picture</a>
</div>
</div>
</div>
</div>
</div>
<!--I have id in my work. but here we don't have id. i need to save particular object in an selected array to another array -->
<button ng-click="setMediaForCurrentPin(selected)" class="btn btn-success" style="margin:50px auto; display:table;">Submit</button>
的的Javascript
$scope.selected = [];
FromOne2Another = function(source, target, item) {
target.push(item);
source.splice(source.indexOf(item), 1);
}
//this is the starting of code where i send the selected pitures from unselected before put request.
$scope.toselected = function(item) {
FromOne2Another($scope.pinMedia, $scope.selected, item);
}
$scope.tosource = function(item) {
FromOne2Another($scope.selected, $scope.pinMedia, item);
}
//this is the ending of above code
//From here i am trying to get the data from the stored media
$scope.toSelectedArray=function(item){
FromOne2Another($scope.other_media, $scope.selected, item);
console.log($scope.pins);
}
如果我在服务中使用这样的话,为什么我会得到Cannot read property 'splice' of undefined
一个我的网站视频,以了解https://nimbus.everhelper.me/client/notes/share/376595/vyEMbEoxsFIfN3X39T5tLdbD8aGfxAgF