我有下表
<table>
<tr>
<td>Id</td>
<td>Name</td>
<td>Lastname</td>
<td>Delete</td>
</tr>
<tr ng-repeat="p in ListPeople">
<td>{{p.id}}</td>
<td>{{p.name}}</td>
<td>{{p.lastname}}</td>
<td>
<button ng-click="deletePerson(p)">Delete</button>
</td>
<td>
<button ng-click="editPerson(p)">Edit</button>
</td>
</tr>
</table>
单击“编辑人”后,我调用一个函数,该函数将该行的那个人对象传递给我,然后我想填充三个附加的输入字段,如下所示:
<input ng-model="person.id"/><br/>
<input ng-model="person.name" /><br />
<input ng-model="person.lastname" /><br />
我的功能如下:
$scope.editPerson = function (person) {
console.log(person);
$scope.person.id = person[0].id;
$scope.person.name = person[1].name;
$scope.person.lastname = person[2].lastname;
};
但是我在控制台中获得了该对象,但是抛出了一个错误,它是:
Error: person[0] is undefined
然后,我将其更改为以下内容:
$scope.person.id = person.id;
$scope.person.name = person.name;
$scope.person.lastname = person.lastname;
并得到错误:$ scope.person是未定义的
尝试这个:
$scope.person = {};
$scope.person.id = person.id;
$scope.person.name = person.name;
$scope.person.lastname = person.lastname;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句