2015-08-30 69 views
-2

所以我有這個簡單的例子如何添加和刪除項目,但問題與編輯。我有這個小提琴:https://jsfiddle.net/b24dqk0r/3/我想要當用戶點擊確定保存該項目array.Any建議?如何編輯項目?

$scope.Save = function (firstName) 
{ 
    $scope.Persons.splice(1,firstName) 
} 
+1

你會刪除你的問題,你得到的答案後,像你以前的人做? –

+0

即時消息不刪除的問題..你會幫我解決我的問題? – None

回答

2
<!DOCTYPE html> 
<html> 
<head> 
<meta charset="ISO-8859-1"> 
<title>Insert title here</title> 
<script src="angular/angular.min.js"></script> 
    <script> 
    var app = angular.module('myApp', []); 
    app.controller('myCtrl', function($scope) { 
     $scope.Persons = []; 
     $scope.firstName = ""; 
     $scope.showEdit = false; 
     $scope.editValue=""; 

     $scope.addItem = function(item) 
    { 
     $scope.Persons.push(item); 
     $scope.firstName =""; 
    } 
     $scope.removeItem = function(person) 
     { 
      $scope.Persons.splice($scope.Persons.indexOf(person), 1); 
     } 
     $scope.editPersons = function (item) { 
     $scope.showEdit = true; 
     $scope.editValue = item; 
     $scope.helpEdit = item; 
     } 
     $scope.Save = function() 
     { 
     editVal = $scope.Persons.splice($scope.Persons.indexOf($scope.helpEdit), 1); 
     $scope.Persons.push($scope.editValue); 
     $scope.editValue=""; 
     $scope.showEdit = false; 
     console.log(editVal); 
     } 

    }); 

    </script> 
</head> 
<body> 
<div ng-app="myApp" ng-controller="myCtrl"> 

First Name: <input type="text" ng-model="firstName"><br> 

<br> 
<ul ng-repeat="person in Persons | filter:search"> 
<li>{{person}}<button type="button" ng-click="removeItem(person)">REMOVE</button> 
<button type="button" ng-click="editPersons(person)">UPDATE</button> 
</li> 

</ul> 
<div ng-show="showEdit"> 
First Name: <input type="text" ng-model="editValue"><br> 
    <button type="button" ng-click="Save()">SAVE</button> 

</div> 
<button type="button" ng-click="addItem(firstName)">ADD</button> 
<br/> 
    <label>SEARCH</label><input type="search" ng-model="search" /> 
</div> 

</body> 
</html> 
+0

我認爲這會幫助你解決你的問題。 – Raju

+0

謝謝.... :) – None