<div class="container" id="assignPackage">
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Group Name</th>
<th style="text-align: center" valign="middle">Minmum Transaction Limit</th>
<th style="text-align: center" valign="middle">Maximum Transaction Limit</th>
<th style="text-align: center" valign="middle">Day Transaction Limit</th>
<th style="text-align: center" valign="middle">No. of Transaction Per Day</th>
</tr>
</thead>
<tbody data-bind="foreach: records">
<tr>
<td data-bind="text:packageName"></td>
<td> <div contenteditable></div> </td>
<td> <div contenteditable></div> </td>
<td> <div contenteditable></div> </td>
<td> <div contenteditable></div> </td>
</tr>
</tbody>
</table>
<br><br>
<button data-bind="click :$root.create" class="btn btn-success">Create Group</button>
<a href="<?php echo base_url(); ?>transaction_limit_setup" class="btn btn-success"><i class="icon-plus icon-white"></i><span>Cancel</span></a>
</div>
<script type="text/javascript" charset="utf-8">
var initialData = jQuery.parseJSON('<?= $packages ?>');//data for building initial table
var vm = function() {
var self = this;
self.records = ko.observableArray(initialData);
$.each(self.records(), function(i, record){
record.packageName = record.packageName;
})
self.create = function()
{
var values = [];
$('#assignPackage tr').each(function(){
var row = [],
group = $(this).find('td:first').html(),
columns = $(this).find('td div');
row['group_name'] = group;
for(var i = 0; i < columns.length; i++) {
var value = $(columns[i]).html();
switch(i) {
case 0:
row['min_trans_limit'] = value;
break;
case 1:
row['max_trans_limit'] = value;
break;
case 2:
row['day_trans_limit'] = value;
break;
case 3:
row['trans_per_day'] = value;
break;
}
}
values.push(row);
});
console.log(values);
var dataToSave = {"groupData" : values};
$.ajax({
type: "POST",
data: dataToSave,
url: "<?= base_url() ?>transaction_limit_setup/saveGroup",
success: function(data) {
alert(data);
},
});
}
}
ko.applyBindings(new vm());
</script>
我想要的是从可编辑的HTML表中获取所有值并在php函数中发布值。这里的列组名是通过数据绑定创建的,其他字段是可编辑的。现在在php函数中我是什么做了
$var = $_POST['groupData'];
echo $var;
我想在php函数中发布整个二维数组,我得到以下错误。
Undefined index: groupData
我该如何解决这个问题。
console.log(values)显示以下内容
[Array[0], Array[0]]0: Array[0]group_name: undefinedlength: 0__proto__: Array[0]concat: function concat() { [native code] }constructor: function Array() { [native code] }entries: function entries() { [native code] }every: function every() { [native code] }filter: function filter() { [native code] }forEach: function forEach() { [native code] }indexOf: function indexOf() { [native code] }join: function join() { [native code] }keys: function keys() { [native code] }lastIndexOf: function lastIndexOf() { [native code] }length: 0map: function map() { [native code] }pop: function pop() { [native code] }push: function push() { [native code] }reduce: function reduce() { [native code] }reduceRight: function reduceRight() { [native code] }reverse: function reverse() { [native code] }shift: function shift() { [native code] }slice: function slice() { [native code] }some: function some() { [native code] }sort: function sort() { [native code] }arguments: (...)get arguments: function ThrowTypeError() { [native code] }set arguments: function ThrowTypeError() { [native code] }caller: (...)get caller: function ThrowTypeError() { [native code] }set caller: function ThrowTypeError() { [native code] }length: 1name: "sort"__proto__: function Empty() {}<function scope>splice: function splice() { [native code] }toLocaleString: function toLocaleString() { [native code] }toString: function toString() { [native code] }unshift: function unshift() { [native code] }Symbol(Symbol.iterator): function ArrayValues() { [native code] }Symbol(Symbol.unscopables): Object__proto__: Object1: Array[0]day_trans_limit: "3"group_name: "Own Account Transfer"length: 0max_trans_limit: "2"min_trans_limit: "1"trans_per_day: "4"__proto__: Array[0]length: 2__proto__: Array[0]