| 제목 | 코드이그나이터로 handsontable을 사용하고 있습니다. ajax로 데이터통신하고있는중에 질문합니다.. | ||
|---|---|---|---|
| 카테고리 | CI 2, 3 | ||
| 글쓴이 | 히디니 | 작성시각 | 2017/05/20 12:56:18 |
|
|
|||
|
안녕하세요!!!! 제가 코드이그나이터로 handsontable를 이용해서 환율관리프로그램은 만들고 있습니다. 현재 ajax post방식으로 data를 보내서 등록을 구현하고 싶은데요... 지금 데이터를 보내면 Array ( [0] => Array ( [0] => 2016-01-01 [1] => 2017-05-12 [2] => 1000.0000 ) [1] => Array ( [0] => 2016-05-12 [1] => 2017-05-12 [2] => 0 ) ) 이렇게 배열로 들어가게 됩니다. 여기서 제가 궁금한점은 [0] => 2016-01-01 [1] => 2017-05-12 [2] => 1000.0000 [3] => 0 [4] => 0.0000 말고 [startdate] => 2016-01-01 [enddate] => 2017-05-12 [currency] => 1000.0000 이런식으로 01234대신 제가 원하는 이름으로 바꿔서 보낼수 있는가하는 점입니다 ㅠㅠ ajax로 데이터통신하는걸 처음해봐서 검색도 어떻게 해야할지 몰라 여기에 질문을 드립니다 ㅠㅠㅠ 완전 생 초보라서 쉽게 설명부탁드려요!! 잘부탁드립니다 ㅠㅠ
밑의 소스는 handsontable 오픈소스를 이용하여 짜본 소스입니다..
var $container = $("#table-list");
var $console = $("#example1console");
var $parent = $container.parent();
var header = [
"시작일자", "마감일자",
<?php foreach ($menu['list'] as $i => $row):?>
"<?= $row['ech_basic'] ?>:<?= $row['ech_currency'] ?>",
<?php endforeach; ?>
];
var data = [
<?php foreach ($list as $i => $row):?>
[
"<?= $row['startdate'] ?>", "<?= $row['enddate'] ?>",
<?php foreach ($menu_basic as $a => $row_units):
$unit = $this->db->where('ech_startdate', $row['startdate'])->where('ech_enddate', $row['enddate'])->where('ech_basic', $row_units)->where('ech_currency', $menu_currency[$a])->get('exchange')->row_array();
if($unit != null){
?>
"<?= $unit['ech_currency_unit'] ?>",
<?php }else{?>
"0",
<?php } endforeach; ?>
],
<?php endforeach; ?>
];
$container.handsontable({
data: data,
rowHeaders: true,
colHeaders: header,
contextMenu: true
});
var handsontable = $container.data('handsontable');
$parent.find('button[name=save]').click(function () {
$.ajax({
url: "/api/exchange/create",
data: {"data": handsontable.getData()}, //returns all cells' data
dataType: 'html',
type: 'POST',
beforeSend: function () {
console.log(handsontable.getData());
},
success: function (res) {
if (res.result === 'ok') {
$console.text('Data saved');
}
else {
$console.text('Save error');
}
},
error: function () {
$console.text('Save error. POST method is not allowed on GitHub Pages. Run this example on your own server to see the success message.');
}
});
});
|
|||
| 다음글 | 엑셀 다운기능 완료후 DB 입력 ? (2) | ||
| 이전글 | 모델은 컨트롤러에서 밖에 안불러 지나요? (2) | ||
|
jcoop
/
2017/05/20 14:04:38 /
추천
0
Ajax로 데이터를 버튼을 누르면 가져오는 것 밖에는 안해봐서 설명은 못하겠네요. Ajax에서는 Json형식으로 데이터를 처리한다고 들었습니다. 배열에 이름을 주는 형태이겠죠. arr[0]이 아니라, "startdate" : 2017-05-10, "enddate" : 2017-05-20 . . .
|
|
곰멍
/
2017/05/20 21:03:38 /
추천
0
var data = []; $.each(handsontable.getData(), function(k, v) { var row = {}; row.startdate = v[0]; row.enddate = v[1]; row.currency = v[2]; data.push(row); }); 이런식으로 데이터를 재가공 후 data: {"data": data} ajax로 데이터를 지정하는 부분에 재가공한 변수를 넣어주시면 될 것 같습니다. |