2015-12-16 2 views
0

У меня есть некоторые задачи. Я хочу убедиться, что каждая задача имеет свойство maximumFundPossible константы $ 1000, свойство currentfund, которое является переменным, поскольку оно будет обновляться по мере того, как будут финансироваться задачи, и свойство бюджета, которое является переменным, но постоянным для каждой задачи. Это свойство элемента задачи должно быть установлено на определенную величину при создании. Думаю, мне придется добавить поле ввода для этой суммы, которое будет установлено при создании задачи? Как ?Как я могу убедиться, что каждый экземпляр моей угловой модели имеет определенные характеристики?

У меня уже есть мои задачи todo, но я застрял, поскольку я на несколько дней новый, чтобы угловатый, и я надеюсь полностью изучить его через этот проект.

Как изменить код, чтобы мои задачи todo имели описанные выше свойства? Кроме того, когда я нажимаю кнопку «делать» или «бесплатно» и т. Д., Будут ли мои текущие представления отслеживать эту конкретную задачу X? Как мне отслеживать эту задачу X, чтобы моя работа, doforfree или любая другая функция, которую я буду использовать, влияет только на конкретную задачу X.

Я знаю, что это слишком много, чтобы спросить, но angularjs просто имеет высокую кривую обучения , Большое спасибо за вашу помощь

Вот мой todoController:

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); 


}; 

}]); 

А вот мое мнение:

<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"> 
    &nbsp;&nbsp;&nbsp;<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()">Fund</button> 
    <span>{{x.todoText}}</span> 
    <button class="doButton" style= "float: right; margin-right: 2px;" ng-click="do()">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>: 
+0

вам действительно нужно, чтобы упростить этот вопрос, поскольку он становится запутаны с бизнес-правилами. во-первых, вы можете передать значение «item» своим действиям, таким как do (item) и fund (item), и удалить (item). Просто измените свою функцию так, чтобы она приняла аргумент элемента. – heavyhorse

ответ

0

здесь просто примера прохождения элемента из нг-повтора на ваши действия:

<div ng-controller="MyCtrl"> 
    <input type="text" ng-model="newMessage"> 
    <button ng-click="addMessage(newMessage)"> 
    Add 
    </button> 
    <ul> 
     <li ng-repeat="message in messages"> 
     {{message}} 
     <button ng-click="remove(message, $index)">remove</button> 
     <button ng-click="uppercase(message, $index)">uppercase</button> 
     <button ng-click="lowercase(message, $index)">lowercase</button> 
     </li> 
    </ul> 
    </div> 

контроллер:

function MyCtrl($scope) { 
    $scope.newMessage = ''; 
    $scope.messages = []; 
    $scope.addMessage = function(msg) { 
    $scope.messages.push(msg); 
    }; 
    $scope.remove = function(msg, index) { 
    $scope.messages.splice(index, 1); 
    }; 
    $scope.uppercase = function(msg, index) { 
    $scope.messages[index] = msg.toUpperCase(); 
    }; 
    $scope.lowercase = function(msg, index) { 
    $scope.messages[index] = msg.toLowerCase(); 
    }; 
} 

взгляните на jsfiddle и действительно поймите, как данные ссылаются на ваши действия. например, я использую неявную переменную $ index для доступа к массиву сообщений.

http://jsfiddle.net/heavyhorse/x4b2w84c/

+0

любая идея, как я буду делать это в моем конкретном случае? – codigomonstruo

 Смежные вопросы

  • Нет связанных вопросов^_^