如何确保我的执行按钮将特定任务标记为请求执行. [英] How do I make sure that my do button will mark the specific task as requested do.
问题描述
我列出了任务,每个任务都有一个执行"按钮和一个资助"按钮.单击Do"按钮或fund"按钮后,我希望将特定任务分配给DoRequested"或FundingProposed"状态.在我的案例中,我只是不知道如何将这些状态添加到特定模型中.
由于我是 angular 的新手,我不知道如何做到这一点.
这是我目前的视图代码:
<div ng-controller="todoController"><h1>任务</h1><div class="item item-input-inset"><label class="item-input-wrapper"><!-- 使用 ng-model 绑定到 todoInput 的实际输入标签 --><input type="text" placeholder="添加新项目" ng-model="todoInput" size="100">标签><!-- 我们的按钮将调用我们的函数来添加一个新的待办事项--><button class="button button-small" ng-click="todoAdd()">添加任务按钮><div ng-repeat="x in todoList"><li class="item item-checkbox"> <label class="checkbox">标签><!-- 这是复选框元素,您将看到它绑定到 items 数组中的 done 设置 --><!-- 当点击它时它调用更新函数将项目更新到它的完成状态--><input type="checkbox" ng-model="x.done" ng-click="update()"/><!-- 这是一个显示项目文本的 span 标签,我使用的是 ng-bind,而不是我们本来可以使用的 span 标签 {{x.todoText}} --><button class="fund-button" style="float: left;"ng-click="fund(x)">基金</button><span>{{x.todoText}}</span><button class="doButton" style="float: right; margin-right: 2px;"ng-click="do(x)">Do</button>
<!-- 移除按钮将调用移除函数并移除所有标记为完成的项目--><button class="button button-block button-assertive" ng-click="remove()">删除选中的任务按钮>
还有我的控制器:
facebookExample.controller('todoController', ['$scope', function($scope) {//初始化待办事项列表数组//如果本地存储为空,则将todolist保存到本地存储$scope.todoList = [];if (localStorage.getItem("mytodos") === null){localStorage.setItem("mytodos", angular.toJson($scope.todoList));}别的{//从本地存储设置todolist$scope.todoList = angular.fromJson(localStorage.getItem("mytodos"));}//添加item函数$scope.todoAdd = function() {//检查文本是否已输入,如果没有则退出if ($scope.todoInput === null || $scope.todoInput === ''){return;}//如果有文本将其添加到数组中$scope.todoList.push({todoText:$scope.todoInput, done:false});//清除文本框$scope.todoInput = "";//将列表重新保存到localstoragelocalStorage.setItem("mytodos", angular.toJson($scope.todoList));};//每个任务限制总资金= $1000//当前资金;最大资金;平衡资金 = $1000-当前//taskX 的变量或列/****************///任务 X 的任务计数器//如果任务分配被管理员批准//将任务计数器设置为 D-63//在到期日向分配给任务 X 的人员发送提醒//除非任务得到资助,否则为钱做按钮被禁用//除非任务已经分配,否则总是启用免费做/****************///只在截止日期更新任务状态//如果 Dtime >到期日//UserX 可以更新任务完成//管理员通过电子邮件通知操作//管理员应在 3 天内批准不同意//管理员可以批准完成或撤消/*********************///管理员批准任务 X 完成//任务 X 更新为完成状态//如果为任务筹集的资金和金额>//如果任务是通过资金资助和完成的,则向 Tasker 发起付款//如果任务是免费完成的,则从公司向管理员发起付款//执行按钮$scope.do = function(){//如果当前用户点击 do,//将当前用户分配给处于待管理审批状态的任务//任务日期的计数器变量由 D-63 启动};$scope.doForFree = function(){//任务分配给状态为pending-aproval-of-admin-assignment-do-for-free 的用户//管理员收到免费请求的通知};//如果管理员批准用户请求执行任务 X 以获取金钱//任务 X 分配给该用户//任务状态分配给 admin-aproved-assignment-for-money//用户收到管理员批准通知//创建/更新任务截止日期//如果管理员批准了请求免费执行任务 X 的用户//任务 X 分配给该用户//任务状态被分配给admin-aproved-assignment-for-free//用户收到管理员批准通知//创建/更新任务截止日期//资金按钮$scope.fund = function(){//将当前用户重定向到paypal支付给You-Serve//最大付款不能超过最大金额 - 已经资助的金额//需要跟踪已经资助的金额//需要跟踪任务成本/价格//如果paypal支付成功//更新已资助金额//更新额外资金的最大金额//更新资金充足的变量/布尔值//发送任务/用户/数量到数据库//如果支付失败,取出被资助状态};$scope.remove = function() {//复制列表var oldList = $scope.todoList;//清晰的列表$scope.todoList = [];//循环遍历列表angular.forEach(oldList, function(x) {//将任何未完成的项目添加到待办事项列表if (!x.done) $scope.todoList.push(x);});//更新本地存储localStorage.setItem("mytodos", angular.toJson($scope.todoList));};//更新函数//这等待100ms将数据存储在本地存储中$scope.update = function() {//单击复选框后100毫秒更新本地存储以允许其处理设置超时(功能(){localStorage.setItem("mytodos", angular.toJson($scope.todoList));},100);};}]);
因此,从快速阅读您的代码来看,您似乎想要通过 ng-click="do(x)" 处理特定项目
并将其添加到 "DoRequested"
或 "FundingProposed"
因此,最简单的方法是通过您正确执行的 ng-click
传递项目.因此,将脚本修改为如下所示:
$scope.DoRequested = [];$scope.fund=function(x){...$scope.DoRequested.push(x);console.log($scope.DoRequested);}
现在每次点击基金按钮时,x
都会被添加到数组中.
这是一个小提琴
I have tasks listed and each task has both a "Do" button and a "Fund" button. Once I click on the "Do" button or "fund" button, I want the specific task to be assigned to a state of "DoRequested" or "FundingProposed". I just do not know how to add these states to the specific model in my case.
As I am new to angular, I have no idea on how to do this.
Here is my view code so far:
<div ng-app="facebookExample" view-title="Tasks">
<div ng-controller="todoController">
<h1>Tasks</h1>
<div class="item item-input-inset">
<label class="item-input-wrapper">
<!-- The actual input tag which is bound to the todoInput using ng-model -->
<input type="text" placeholder="Add New Item" ng-model="todoInput" size="100">
</label>
<!-- Our button thay will call our funtion to add a new todo item -->
<button class="button button-small" ng-click="todoAdd()">
Add Task
</button>
</div>
<div ng-repeat="x in todoList">
<li class="item item-checkbox">
<label class="checkbox">
</label>
<!-- this is the checkbox element, you will see it is bound to the done setting in the items array -->
<!-- When clicked it calls the update function to update the item to its done status -->
<input type="checkbox" ng-model="x.done" ng-click="update()"/>
<!-- this is a span tag that shows the item text, I am using ng-bind, instead of the span tag we could have used {{x.todoText}} as well -->
<button class="fund-button" style= "float: left;" ng-click="fund(x)">Fund</button>
<span>{{x.todoText}}</span>
<button class="doButton" style= "float: right; margin-right: 2px;" ng-click="do(x)">Do</button>
</li>
</div>
<!-- the remove button will call the remove function and remoave all items that are marked done -->
<button class="button button-block button-assertive" ng-click="remove()">Remove Checked Tasks
</button>
</div>
</div>
And my controller:
facebookExample.controller('todoController', ['$scope', function($scope) {
// Initialize the todo list array
//if local storage is null save the todolist to local storage
$scope.todoList = [];
if (localStorage.getItem("mytodos") === null)
{
localStorage.setItem("mytodos", angular.toJson($scope.todoList));
}else
{
//set the todolist from local storage
$scope.todoList = angular.fromJson(localStorage.getItem("mytodos"));
}
// Add an item function
$scope.todoAdd = function() {
//check to see if text has been entered, if not exit
if ($scope.todoInput === null || $scope.todoInput === ''){return;}
//if there is text add it to the array
$scope.todoList.push({todoText:$scope.todoInput, done:false});
//clear the textbox
$scope.todoInput = "";
//resave the list to localstorage
localStorage.setItem("mytodos", angular.toJson($scope.todoList));
};
// Each task is limited to limit total funding = $1000
//current funding ; max funding; ballance funding = $1000-current
// Variables or columns for taskX
/****************/
// Task Counter for Task X
// If task-assignment is aproved by admin
// Set Task Counter to D-63
// Send reminder to Person assigned for task X in Due Date
// Do for money button is diabled unless task is funded
// Do for free is always enabled unless task is already assigned
/**************/
//Updating state of task to done only on due date
// if Dtime > DueDate
// UserX can update task to done
// Admin is notified by email of the action
// Admin should aprove of disaprove within 3 days
// Admin can aprove to Done or Undone
/*******************/
// Admin aproves of Task X to done
// Task X is updated to state of done
//if for moeny and amount raised for task >
// Payment is initiated to Tasker if task was funded and done for money
// Payment initiated from Company to Admin if task was done for free
//Do button
$scope.do = function(){
// If current user clicks do,
// Assign the current user to the task with a state of pending admin aproval
// Counter variable for dute date is initiated with D-63
};
$scope.doForFree = function(){
// Task is assigned to user with a state of pending-aproval-of-admin- assignment-do-for-free
// Admin is notified of do-for-free-request
};
// if admin aproves user that requested to do task X for money
// task X is assigned to that user
// state of task is assigned to admin-aproved-assignment-for-money
// the User is notified of admin aproval
// Task due date is created/updated
// if admin aproves user that requested to do task X for free
// task X is assigned to that user
// state of task is assigned to admin-aproved-assignment-for-free
// the User is notified of admin aproval
// Task due date is created/updated
//fund button
$scope.fund = function(){
//Redirect current user to paypal for payment to You-Serve
// Maximum payment cannot exceed Maximum amount - what 's already funded
// Need to keep track of already funded amount
// Need to keep track of task cost/price
// If paypal payment was done successfully
// Update already funded amount
// Update maximum amount for extra funding
// update the fully funded variable/boolean
// Send task/user/amount to database
// If payment fails, take out state of being funded
};
$scope.remove = function() {
//copy list
var oldList = $scope.todoList;
//clear list
$scope.todoList = [];
//cycle through list
angular.forEach(oldList, function(x) {
//add any non-done items to todo list
if (!x.done) $scope.todoList.push(x);
});
//update local storage
localStorage.setItem("mytodos", angular.toJson($scope.todoList));
};
//The Update function
//This waits 100ms to store the data in local storage
$scope.update = function() {
//update local storage 100 ms after the checkbox is clicked to allow it to process
setTimeout(function(){
localStorage.setItem("mytodos", angular.toJson($scope.todoList));
},100);
};
}]);
So from a quick read through your code it seems what you want is to process the specific item by ng-click="do(x)"
and add it to "DoRequested"
or "FundingProposed"
So the simplest way would be to pass the item via ng-click
which you did correctly. So modify the script to something like this :
$scope.DoRequested = [];
$scope.fund=function(x){
.
.
.
$scope.DoRequested.push(x);
console.log($scope.DoRequested);
}
now each time you click the fund button , x
is added to array.
Here's a fiddle
这篇关于如何确保我的执行按钮将特定任务标记为请求执行.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!