使用拼接移除阵列中的项目时遇到问题。我似乎无法让它工作,它总是返回一个
-1
价值
json对象
{
"_id": "5a61ad6fd5df1761dd2eb1f1",
"branch": "Lucban",
"__v": 0,
"building": [
{
"name": "mhq",
"floors": [
"ground floor",
"2nd floor"
]
}
],
"dateCreated": "2018-01-19T08:33:51.761Z"}
html
<span class="badge badge-pill badge-primary text-capitalize" ng-repeat="floor in vm.selectedItem.building[0].floors">{{floor}}
<i class="fa fa-times-circle-o" aria-hidden="true" ng-click="vm.removeItem($index)"></i></span>
控制器
vm.removeItem = removeItem;
function removeItem(data) { // data is $index of the object
var index = vm.selectedItem.building[0].floors.indexOf(data); //always throwing -1
console.log(index);
vm.selectedItem.building[0].floors.splice(index, 1);
}