Solved

Need to read from table created with ng-repeat

Posted on 2013-12-02
3
393 Views
Last Modified: 2013-12-03
I have the below data that is filled using ng-repeat

<tr ng-repeat="task in taskMasterList" on-repeat-finished>
	<td><input type="checkbox" /></td>
	<td>{{ task.TaskCategory }}</td>
	<td>{{ task.TaskDescription }}</td>
	<td><input ng-model="dueDate"></td>
	<td>
		<select ng-model="task.TaskStatus" >                                         
			<option value="1">Open</option>
			<option value="2">In Progress</option>
			<option value="3">Complete</option>
			<option value="4">Deleted</option>
		</select>
	</td>
</tr>
<button ng-click="MasterTaskListSave($event)">Save</button>

Open in new window

-----------------------

This code successfully gets the data from the database (A web service is set up)



var masterTasks = TasksService.GetListingMasterTasks(
{}
, function (data) {
	$scope.taskMasterList = data;          
}
, function (data, status) {
	alert('Failed');
});

Open in new window


I now need to look through the data and get all the rows that are checked
where       <td><input type="checkbox" /></td>  and get the valuses in

<select ng-model="task.TaskStatus"

Any advice is appreciated
0
Comment
Question by:charlesbaldo
3 Comments
 
LVL 7

Assisted Solution

by:cstsang
cstsang earned 100 total points
ID: 39691845
I give you a sample code for your reference,hope it can help:
<html>
<body>
	<script language=javascript>
		function hh()
		{
			var table=document.getElementById("qq"); //get the table object
			var dropDownBox,cells,checkBox;
			for (i=0;i<table.rows.length;i++)   //loop all rows
			{
				cells=table.rows[i].cells;
				checkBox=cells[0].firstChild; //get the check box object
				isCheck=checkBox.checked;     //check whether the check box is checked
				dropDownBox=cells[1].firstChild; //get the dropdown box object
				dropDownBoxValue=dropDownBox.options[dropDownBox.selectedIndex].value; //get the dropdown box value
				alert("Check box is checked "+isCheck+",Drop Down Box Value="+dropDownBoxValue);
			}
		}	
	</script>
	<table id="qq">
		<tr>
			<td><input type="checkbox" checked/></td>
			<td><select>
				 <option selected value="1">Open</option>
                  <option value="2">In Progress</option>
                  <option value="3">Complete</option>
                  <option value="4">Deleted</option>
            	</select>
      		</td>
		</tr>
		<tr>
			<td><input type="checkbox" /></td>
			<td><select>
				 <option  value="1">Open</option>
                  <option selected value="2">In Progress</option>
                  <option value="3">Complete</option>
                  <option value="4">Deleted</option>
            	</select>
      		</td>
		</tr>
	</table>	
	<input type=button onclick="hh()" value="go">
</body>
</html>	

Open in new window

0
 
LVL 82

Accepted Solution

by:
leakim971 earned 400 total points
ID: 39692214
With : <input type="checkbox" ng-model="task.isChecked" />

You may use something like :
        $scope.MasterTaskListSave = function(evt) {
            var taskListToSave = [];
            for(var i=0;i<$scope.taskMasterList.length;i++) {
                var task = $scope.taskMasterList[i];
                if(task.isChecked) {
                    taskListToSave.push(task);
                    // for the demo
                    alert(task.TaskStatus);
                }
            }
            // taskListToSave contains all selected task with their TaskStatus
            // you can send it to server side to save it now
            save(taskListToSave);
        }

Open in new window

0
 

Author Closing Comment

by:charlesbaldo
ID: 39692387
Thank you all
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question