我使用laravel揹包,我有點卡住現在:插入選中複選框
- >我想從表中加載的基礎上,一些複選框之前的下拉結果。
喜歡說我有一個名爲exercise_type
的字段,它是一個下拉列表,下拉列表中的所有選項都存儲在一個表格中,每個exercise_type
有10個與其相關的練習。
這裏value
表是exercise_type
並且每個value
有10倍以上的值。
這裏是我如何在Crudcontroller中添加這個exercise_type
字段。
$this->crud->addField([ // select_from_array
'name' => 'exercise1_type',
'label' => "Exercise 1",
'type' => 'select2',
'entity' => 'Exercise_group',
'attribute' => 'value',
'model' => 'App\Models\Exercise_group',
//'allows_null' => false,
'attributes' => [
'id' => 'exercise',
'OnChange' => 'getexercise()',
]
// 'allows_multiple' => true, // OPTIONAL; needs you to cast this to array in your model;
], 'update/create/both');
我能夠從表中加載值直到這裏。
然後我overrided創建視圖的視圖,並將此帶來的複選框在阿賈克斯成功的功能。
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
function getexercise(){
var exercise = $('#exercise').val();
alert(exercise);
$.ajax({
url : "../../getexercise",
type : "POST",
data : { id : exercise },
success: function(response){
// what to put here to bring checkboxes with the name of exercises
as in table
}
});
};
這裏是我的路線:
Route::post('/getexercise','[email protected]');
這裏是我的BlahController.php
public function getexercise(Request $request){
$id = $_POST['id'];
$exercises = Exercise_group::where('id', $id)->first();
$exercise_id = $exercises->id;
$exercise_1 = $exercises->exercise1;
$exercise_2 = $exercises->exercise2;
$exercise_3 = $exercises->exercise3;
$exercise_4 = $exercises->exercise4;
$exercise_5 = $exercises->exercise5;
$exercise_6 = $exercises->exercise6;
$exercise_7 = $exercises->exercise7;
$exercise_8 = $exercises->exercise8;
$exercise_9 = $exercises->exercise9;
$exercise_10 = $exercises->exercise10;
return response()->json([
'exercise_id' => $exercise_id,
'exercise1' => $exercise_1,
'exercise2' => $exercise_2,
'exercise3' => $exercise_3,
'exercise4' => $exercise_4,
'exercise5' => $exercise_5,
'exercise6' => $exercise_6,
'exercise7' => $exercise_7,
'exercise8' => $exercise_8,
'exercise9' => $exercise_9,
'exercise10' => $exercise_10,
//'state' => 'CA'
]);
}
我不能夠在阿賈克斯成功的一切功能添加複選框工作得很好。我嘗試了這些鏈接,但他們沒有工作這樣:
編輯::
現在複選框都這樣工作:
$.each(response, function (key, value) {
var li = $('<li><input type="checkbox" name="' + key + '" id="' + key + '"/>' +
'<label for="' + key + '"></label></li>');
li.find('label').text(value);
$('#wkslist').append(li);
console.log(value);
$('#exercise_detail').val(value);
});
但他們沒有以一種很好的方式顯示,所以如果我想添加這些複選框值在揹包laravel另一個下拉作爲我試圖例子,但不工作:
$('#exercise_detail').val(value);
$this->crud->addField([ // Select2Multiple = n-n relationship (with pivot table)
'name' => "exercise1_type_detail",
'label' => "Exercise 1 : Detail",
'type' => 'select2_multiple',
'attributes' => [
'id' => 'exercise_detail',
//'OnChange' => 'getexercisedetail()',
],
], 'update/create/both');
我真的不明白你想說什麼..你能更簡單地理解或詳細說明你的問題,請詳細一點。 –
@FaisalMehmoodAwan在揹包laravel我已經重寫了創建視圖,並添加了ajax調用成功的地方,我想根據所選擇的練習類型調用複選框查看錶格和鏈接。我不能添加複選框 –