【发布时间】:2016-09-23 07:55:26
【问题描述】:
我有一个数组
$scope.items = [{id:1 , name:'john'},{id:2, name:'doe'}];
现在我正在从数组中过滤对象
$scope.newItem = $filter('filter')($scope.items, {id: 1})[0];
然后,我在更新表单中使用 $scope.newItem 但是当我输入字段时,原始数组 ($scope.items) 中的对象也在发生变化。任何人都可以帮助我做错了什么。
更多描述,
我正在执行两个步骤。在第一步中,我获取所有项目并存储在 $scope.items 中。然后在第二步中,单击项目列表中的编辑时,我在此处过滤该 ID 的对象,让 1,
$scope.newItem = $filter('filter')($scope.items, {id: 1})[0];
然后在显示新项目后我想更新它。当我输入一些内容来更新 newitem 中的字段时,原始数组中的原始对象也在更新...
【问题讨论】:
-
请记住,我们对您在做什么一无所知。到目前为止,您的问题很难理解。
标签: javascript angularjs filter angularjs-scope