[英]jquery dialog in yii2
I have a js in yii2 like this : 我在yii2中有一个js像这样:
<?php
$getDetailItem = \Yii::$app->getUrlManager()->createUrl(['it/request/get-item-detail']);
$js = <<<JS
var \$pop = $("input[type='checkbox'][name='ItemRequest[id][]']");
$("input[type='checkbox'][name='ItemRequest[id][]']").click(function(e){
$.ajax({
url : '$getDetailItem',
type : 'post',
data : {id : $(this).val()},
dataType : 'text',
success : function(response){
krajeeDialog.confirm("Your Choice : <br>" +
response
, function (result) {
if (result) {
alert('Anda memilih Item : ' + response);
}
});
}
});
});
JS;
$this->registerJs($js)
?>
if you can see in the line : 如果您可以在行中看到:
$getDetailItem = \Yii::$app->getUrlManager()->createUrl(['it/request/get-item-detail']);
will be produce a json like this : 将产生这样的json:
[{
"id": "1",
"item_request_id": "1",
"nama_detail": "Create Login Novell"
}, {
"id": "2",
"item_request_id": "1",
"nama_detail": "Create Email Baru"
}, {
"id": "3",
"item_request_id": "1",
"nama_detail": "Disable / Hapus Login Novell"
}, {
"id": "4",
"item_request_id": "1",
"nama_detail": "Disable / Hapus Email"
}]
My question is, how to display the response.nama_detail in dialog as checklistbox ? 我的问题是,如何在对话框中将response.nama_detail显示为复选框?
I use thi krajee plugin : kartik / krajee 我使用thi krajee插件: kartik / krajee
Then user can choose the items nama_detail 然后用户可以选择项目nama_detail
Any help it so appreciate... 任何帮助,请感激...
Try parsing that JSON response and format data by your needs by looping through array you will get, I used jquery each method for this. 尝试通过遍历将要获得的数组来解析JSON响应并根据需要格式化数据,为此我使用了jquery的每种方法 。
Hopefully I did not make any misstake there, this is not tested, if you find any error, please feel free to comment or edit. 希望我没有在这里犯任何错误,这未经测试,如果发现任何错误,请随时发表评论或编辑。
// ...
success : function(response){
var parsed = JSON.parse(response);
var output = "";
$.each(parsed, function(index, value){
output .= value['nama_detail'] . ", ";
});
krajeeDialog.confirm("Your Choice : <br>" +
output
, function (result) {
if (result) {
alert('Anda memilih Item : ' + response);
}
});
// ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.