Php laravel 5.2动态下拉列表
我有一个活动,我想从艺术家表中添加艺术家。 我想通过使用一个下拉列表来实现这一点,其中需要填充艺术家的名字,并且他们的名字旁边有一个小“+”来添加其他艺术家。执行此操作后,将出现第三个可传递表,其中事件id和艺术家id应作为外键插入。 当我创建事件时 我认为:Php laravel 5.2动态下拉列表,php,mysql,list,laravel,dropdown,Php,Mysql,List,Laravel,Dropdown,我有一个活动,我想从艺术家表中添加艺术家。 我想通过使用一个下拉列表来实现这一点,其中需要填充艺术家的名字,并且他们的名字旁边有一个小“+”来添加其他艺术家。执行此操作后,将出现第三个可传递表,其中事件id和艺术家id应作为外键插入。 当我创建事件时 我认为: <div class="form-group"> <label for="task-artist" class="col-sm-3 control-label">Artist:</label> <
<div class="form-group">
<label for="task-artist" class="col-sm-3 control-label">Artist:</label>
<div class="col-sm-6">
<select name="artist" id="artist" class="form-control input-sm">
<option value=""></option>
@foreach($artists as $artist)
{{$artist->stage_name}}
@endforeach
</select>
</div>
</div>
我该怎么办?
请帮忙。Javascript是您的朋友 让我写一些步骤,你可以按照这些步骤来实现你的目标: 我有Div标签和 2使用javascript中的$.get函数从控制器获取动态值 3$。每个循环遍历数据并在选择输入字段中显示 4在选择您提到的值或单击+按钮时,执行另一个Javascript调用以将艺术家添加到事件中 例如:
HTML
<div class="uk-margin-bottom">
<div id="your select dropdown"></div>
</div>
JAVASCRIPT
$("#artist").change(function() {
getArtists();
});
function getArtist() {
var artist= $('#your div id');
artist.empty();
var code = '';
$.get("/url/" + variable_id, function(data) {
artist.empty();
console.log(data);// once you create route and controller you should see your artists lists here
code += '<label for="event_id" class="uk-form-label">Select Artist</label><select class="uk-width-1-1" name="artist_name" id="artist_name" value="select">';
code += '<option value="">Select Artists</option>';
$.each(data.artist, function(index, value) {
code += '<option value="' + value.artist_name+ '">' + value.artist_name + '</option>';
});
code += '</select>
artist.append(code);
});
}
创建一个表单,将javascript添加到控制器的post Artister中,并将数据存储到events表中。试着看看你是否能实现并遵循我的步骤。Javascript是你在这里的朋友 让我写一些步骤,你可以按照这些步骤来实现你的目标: 我有Div标签和 2使用javascript中的$.get函数从控制器获取动态值 3$。每个循环遍历数据并在选择输入字段中显示 4在选择您提到的值或单击+按钮时,执行另一个Javascript调用以将艺术家添加到事件中 例如:
HTML
<div class="uk-margin-bottom">
<div id="your select dropdown"></div>
</div>
JAVASCRIPT
$("#artist").change(function() {
getArtists();
});
function getArtist() {
var artist= $('#your div id');
artist.empty();
var code = '';
$.get("/url/" + variable_id, function(data) {
artist.empty();
console.log(data);// once you create route and controller you should see your artists lists here
code += '<label for="event_id" class="uk-form-label">Select Artist</label><select class="uk-width-1-1" name="artist_name" id="artist_name" value="select">';
code += '<option value="">Select Artists</option>';
$.each(data.artist, function(index, value) {
code += '<option value="' + value.artist_name+ '">' + value.artist_name + '</option>';
});
code += '</select>
artist.append(code);
});
}
创建一个表单,将javascript添加到控制器的post Artister中,并将数据存储到events表中。试着看看你是否能做到,并遵循我的步骤