0
我想通读数组。将员工编号与表格匹配,并在匹配表格中填写奖励值。jquery interate数组并匹配html表中的值并填写列
<script type="text/javascript" src="jquery.js"></script>
<script>
$(document).ready(function() {
// note that employee may get 0,1, or more bonuses
myArray =
{"employees": [
{"employee": "1231", "bonus":100},
{"employee": "1232", "bonus":200},
{"employee": "1233", "bonus":300}
{"employee": "1233", "bonus":33}
]
}
$.each(myArray.employees, function(index) {
console.log(this.employee);
// having problem here...
$("#myTable:has(td:contains(this.employee)").each(function() {
console.log("found");
// then write to 2nd cell in table next to employee#
// assume that employee number in table is unique
});
});
});
</script>
<table id='myTable' border='1px'>
<tr>
<th>Employee</th>
<th>Bonus</th>
</tr>
<tr>
<td>1232</td>
<td> </td>
</tr>
<tr>
<td>1231</td>
<td> </td>
</tr>
<table>
答案是了不起的! –