使用一个拖放插件传递数据,ondrop
事件获取数据,如下
Ctrl
var streamArr = [];
$scope.onDrop = function (data, dragElement, dropElement, event) {
streamArr.push({'userId':userId,'divid':divId,'userName':userName,'streamingState':$rootScope.route});
});
输出
10
divPictureBox00
User1
live
现在,每当用户放下东西时,我都需要将数据推送到一个数组中,这样得到的itesm就会低于
streamArr: [
{userId: 10, divId: 'divPictureBox00', userName: 'User1', streamingState:'live'},
{userId: 11, divId: 'divPictureBox01', userName: 'User2', streamingState:'live'},
{userId: 12, divId: 'divPictureBox02', userName: 'User3', streamingState:'recorded'},
{userId: 10, divId: 'divPictureBox00', userName: 'User1', streamingState:'live'},
]
但数据并没有被推送到该数组中。我该怎么做?
这是因为您始终在处理同一个对象。尝试在每次调用函数时创建一个新对象,然后在数组中推送该对象。
var streamArr = [];
$scope.onDrop = function (data, dragElement, dropElement, event) {
var obj = new Object();
obj.userId = userId;
obj.divId = divId;
obj.userName = userName;
obj.streamingState = $rootScope.route;
streamArr.push(obj);
});