[英]jquery dialog in yii2
我在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)
?>
如果您可以在行中看到:
$getDetailItem = \Yii::$app->getUrlManager()->createUrl(['it/request/get-item-detail']);
將產生這樣的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"
}]
我的問題是,如何在對話框中將response.nama_detail顯示為復選框?
我使用thi krajee插件: kartik / krajee
然后用戶可以選擇項目nama_detail
任何幫助,請感激...
嘗試通過遍歷將要獲得的數組來解析JSON響應並根據需要格式化數據,為此我使用了jquery的每種方法 。
希望我沒有在這里犯任何錯誤,這未經測試,如果發現任何錯誤,請隨時發表評論或編輯。
// ...
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.