我正在使用角度js,并且很难弄清楚如何更新值。我试过,但没有成功。我会发布我的js文件,如果有人知道我的问题,将非常感谢帮助。这只是updateTask,我遇到了问题。
function TodoCtrl($scope) {
$scope.todos = [
{text:'task1', text2:'Mow the lawn', selected:false},
{text:'task2', text2:'Wash the car', selected:false}
];
$scope.getTotalTodos = function () {
return $scope.todos.length;
};
$scope.addTask = function () {
$scope.todos.push({text:$scope.formTodoName, text2:$scope.formTodoDescription, selected:false});
$scope.formTodoName = '';
$scope.formTodoDescription = '';
};
$scope.removeTask = function () {
$scope.todos = _.filter($scope.todos, function(todo){
return !todo.selected;
});
};
$scope.updateTask = function () {
if ($scope.todos.selected:true){
$scope.todos.put({text:$scope.formTodoName, text2:$scope.formTodoDescription, selected:false});
$scope.formTodoText = '';
};
};
}
的index.html
<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<title>Todo App</title>
<header>Todo App</header>
<link rel="stylesheet" href="css/reset.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<html ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<script src="//use.edgefonts.net/vast-shadow:n4:all.js"></script>
<script src="//use.edgefonts.net/vast-shadow:n4:all;megrim.js"></script>
</head>
<body>
<div class="todo-wrapper" ng-controller="TodoCtrl">
<h2>You have <span class="emphasis">{{getTotalTodos()}}</span> tasks</h2>
<ul>
<li ng-repeat="todo in todos">
<input type="checkbox" ng-model="todo.selected"/>
<span class="selected-{{todo.selected}}">{{todo.id}} {{todo.text}}: {{todo.text2}} {{todo.date_created}}</span>
</li>
</ul>
<form>
<input class="add-input" placeholder="task name" type="text" ng-model="formTodoName" ng-model-instant />
<input class="add-input2" placeholder="task decription" type="text" ng-model="formTodoDescription" ng-model-instant />
<button class="add-btn" ng-click="addTask()"><h2>Add</h2></button>
</form>
<form>
<input type="text" ng-model="task.text"></input>
<button class="update-btn" ng-click="updateTask()"><h3>Update Task</h3></button>
<button class="clear-btn" ng-click="removeTask()">Remove Task</button>
</div>
</body>
</html>
<script src='http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js'></script>
<script src="js/index.js"></script>
</body>
</html>