以下是我尝试的示例代码。
<?php
require "init.php";
$json = file_get_contents('php://input');
//$data = json_decode($json,true);
// remove the ,true so the data is not all converted to arrays
$data = json_decode($json);
// Now process the array of objects
foreach ( $data as $inv ) {
$custInfo = $inv->custInfo;
$rate = $inv->rate;
$weight= $inv->weight;
$desc= $inv->desc;
$makingAmt= $inv->makingAmt;
$vat= $inv->vat;
$itemTotal= $inv->itemTotal;
$sum_total= $inv->sum_total;
$barcode= $inv->barcode;
$net_rate= $inv->net_rate;
$date= $inv->date;
$invoiceNo= $inv->invoiceNo;
$bill_type= $inv->bill_type;
$sql = "INSERT INTO selected_items
(custInfo, invoiceNo, barcode, desc,
weight, rate, makingAmt,net_rate,
itemTotal,vat,sum_total,bill_type,date)
VALUES
('$custInfo','$invoiceNo','$barcode','$desc',
'$weight','$rate','$makingAmt','$net_rate',
'$itemTotal','$vat','$sum_total','$bill_type','$date')";
$res = mysql_query($sql,$con);
if(!$res){
$result = new stdClass();
$result->status = false;
$result->msg = mysql_error();
echo json_encode($result);
exit;
}
}
?>
以下是来自server-link的json数据。
{
name : 'scopeName',
index : 'scopeName',
width: '400px',
resizable : true,
align : "left",
editable : true,
edittype : "select",
editoptions : {
value : getSequenceNumbers()
},
editrules : {
required : true
}
function:
function getSequenceNumbers() {
alert("here123");
$.getJSON("http://localhost:8039/ReleaseManagementApp/releasemgmt/config/Q2FY16/scope", null, function(data) {
if (data != null) {
alert("here");
//construct string.
//(or the server could return a string directly)
for (var i=0; i<data.length; i++) {
sel.append('<option value="' + data[i].scopeName + '">' + data[i].scopeName + '</option>');
}
}
});
}
我想知道我是否可以将scopeName从上面的响应填充到jqgrid作为选择标签。
答案 0 :(得分:0)
相反,我建议您使用自定义格式化程序:
{
name : 'scopeName',
index : 'scopeName',
width: '400px',
resizable : true,
align : "left",
formatter:getSequenceNumbers // <----use the function here
}
现在你可以从这个函数返回一个select元素:
function getSequenceNumbers() {
alert("here123");
var sel = '<select>';
sel +='<option value="select">Select...</option>';
$.getJSON("url", null, function(data) {
if (data != null) {
alert("here");
//construct string.
//(or the server could return a string directly)
for (var i=0; i<data.length; i++) {
sel += '<option value="' + data[i].scopeName + '">'
+ data[i].scopeName + '</option>';
}
sel +="</select>";
}
});
return sel;
}