gpt4 book ai didi

javascript - 如何使用一个id将多个值传递到模式中

转载 作者:行者123 更新时间:2023-11-28 05:39:06 26 4
gpt4 key购买 nike

我在JQXgrid中创建了按钮渲染器,当单击按钮时,它将数据传递到 Controller , Controller 发送到模型,然后返回来自mysql的数据结果。

这是我的 View 代码部分按钮渲染器:

var button_renderer = function (row, columnfield, value, defaulthtml, columnproperties) {
var kode_keramik = $('#jqxgrid').jqxGrid('getcelltext', row, "kode_keramik");
button = '<a href="#modal_details" class="btn btn-xs btn-success view_details" id="'+ kode_keramik +'" >Proceed</a>';
return button;
};

这是我将数据传递到 Controller 的 View 代码部分:

$(document).on('click', ".view_details", function() {

//alert("aaa");
var url = "<?php echo base_url().'getGlazeMM/ajax_get_item_list'?>";
kode_keramik = this.id;

$.post(url, {kode_keramik: kode_keramik} ,function(data) {
$('.modal-body').empty();
$('.modal-body').append(data);
$('#modal_details').modal();
});

});

这是我的 Controller :

public function ajax_get_item_list(){

$data['post'] = $_POST;
$kode_keramik = $_POST['kode_keramik'];
//$buyer = $_POST['buyer'];

$this->load->model('get_glaze');

$data['item_list'] = $this->get_glaze->action_ajax_get_item_list( $data['post'] );

if ($data['item_list']){

echo "<table class='table table-bordered'>
<tr>
<th>Inspect Date</th>
<th>Item Code</th>
<th>Type</th>
<th>Hasil KW1</th>
<th>Total Inspek</th>
<th>Aktual Yield</th>
<th>Buyer</th>
</tr>";

foreach ($data['item_list'] as $key => $value) {

echo "<tr>";
echo "<td>".$value['inspect_date']."</td>";
echo "<td>".$value['item_code']."</td>";
echo "<td>".$value['sell_type']."</td>";
echo "<td>".$value['hasil_kw1']."</td>";
echo "<td>".$value['total_inspek']."</td>";
echo "<td>".$value['aktual_yield']." %</td>";
echo "<td>".$kode_keramik."</td>";
echo "</tr>";

}

echo "</table>";

} else {
echo "Data tidak ditemukan";
}

}

最大的问题是如何从 view_details"id="'+ kode_keramik +'" + SECOND VALUE 传递多个数据

var button_renderer = function (row, columnfield, value, defaulthtml, columnproperties) {
var kode_keramik = $('#jqxgrid').jqxGrid('getcelltext', row, "kode_keramik");
button = '<a href="#modal_details" class="btn btn-xs btn-success view_details" id="'+ kode_keramik +'" >Proceed</a>';
return button;
};

进入:

var url = "<?php echo base_url().'getGlazeMM/ajax_get_item_list'?>";
kode_keramik = this.id;
***SECOND VALUE;***

$.post(url, {kode_keramik: kode_keramik, ***SECOND VALUE***} ,function(data) {

直到 Controller :

public function ajax_get_item_list(){

$data['post'] = $_POST;
$kode_keramik = $_POST['kode_keramik'];
$***SECOND VALUE*** = $_POST['***SECOND VALUE***'];

最佳答案

您可以将数据格式化为一个 JSON 对象,并将其放入自定义 html 属性中。

示例

请小心单引号双引号转义

var button_renderer = function (row, columnfield, value, defaulthtml, columnproperties) {
var kode_keramik = $('#jqxgrid').jqxGrid('getcelltext', row, "kode_keramik");
button = "<a href='#modal_details' class='btn btn-xs btn-success view_details' data-custom='{\"kode_keramik\": \"" + kode_keramik + "\", \"second\": \"value\"}'>Proceed</a>";
return button;
};

使用jQuery检索我们的对象

$(document).on('click', ".view_details", function() {
//alert("aaa");
var url = "<?php echo base_url().'getGlazeMM/ajax_get_item_list'?>";

var obj = $(this).data('custom'); // get object using jQuery

$.post(url, obj ,function(data) {
$('.modal-body').empty();
$('.modal-body').append(data);
$('#modal_details').modal();
});

});

它将自动解析对象。

关于javascript - 如何使用一个id将多个值传递到模式中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39076506/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com