Solved

Need to read from table created with ng-repeat

Posted on 2013-12-02
3
391 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now