【发布时间】:2016-03-25 12:45:48
【问题描述】:
我正在使用淘汰赛js并将所有数据放在一个数组上,然后像这样放在这个表上。
self.allchildrendata = ko.observableArray();
self.viewAllUserChildrenCard = function () {
$.ajax({
type: 'POST',
url: BASEURL + '/index.php/main/childrenCardInfo',
contentType: 'application/json; charset=utf-8',
dataType :'json'
})
.done(function(childrencards) {
self.allchildrendata.removeAll();
$.each(childrencards, function (index, childrencard) {
self.allchildrendata.push(childrencard);
console.log(self.allchildrendata());
});
})
.fail(function(xhr, status, error) {
alert(status);
})
.always(function(data){
});
};
self.viewAllUserChildrenCard();
所以接下来我想点击 rebecca 的 add money 按钮并想发送 rebecca 的 orig id,这样我就可以用它在数据库中找到她并添加钱,但我不确定如何发送orig_id,我试过这种方式。
self.giveCashtoChild = function(){
$.ajax({
type: 'POST',
url: BASEURL + '/index.php/main/addUserChildrenCash' + "/" + self.allchildrendata().orig_id ,
contentType: 'application/json; charset=utf-8'
})
.done(function() {
})
.fail(function(xhr, status, error) {
alert(status);
})
.always(function(data){
});
}
这是我在每个按钮上都有一个数据绑定的 html 代码,因此我可以发送原始 ID。
<tbody data-bind="foreach: allchildrendata">
<tr>
<td class="text-center"><span data-bind="text : $data.children_name"></span></td>
<td class="text-center"><span data-bind="text : $data.daugther_son"></span></td>
<td class="text-center"><span data-bind="text : $data.amount"></span> $</td>
<td class="text-center"><a href="#" data-bind="click : $root.giveCashtoChild"><span class=" glyphicon glyphicon-send"></span></a></td>
<td class="text-center"><a href="<?php echo base_url(); ?>index.php/main/takeAway"><span class=" glyphicon glyphicon-trash"></span></a></td>
</tr>
</tbody>
所以基本上我需要帮助来确定我点击了哪个家庭成员并将其发送给那个家庭成员 orig_id
【问题讨论】:
标签: javascript jquery ajax knockout.js