将项目从一个数组推送到Angular中的另一个数组 [英] Push Item From One Array Into another Array in Angular

查看:113
本文介绍了将项目从一个数组推送到Angular中的另一个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用AngularJS编写应用程序并想知道如何将项目从一个数组推送到另一个数组。


I am programming an app with AngularJS and wanted to know how to push an item from one array into another array.

这是示例代码:

$scope.tasks = [
     {title: "Do the dishes"},
     {title: "Walk the dog"},
];
$scope.addToTasksDone = function() {// IM FAILNG HERE};
$scope.tasksDone = [];

如何将值为Do the dishes的项目推送到tasksDone数组?

How can I push the item with value "Do the dishes" to the tasksDone array?

推荐答案

$scope.tasks = [
{title: "Do the dishes"},
{title: "Walk the dog"},
];
$scope.tasksDone = [];
$scope.addToTasksDone = function(index) {// IM FAILNG HERE};
$scope.tasksDone.push($scope.tasks[index]);
}

这篇关于将项目从一个数组推送到Angular中的另一个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆