【发布时间】:2018-04-11 06:14:30
【问题描述】:
我在我的多选应用程序中实现了bootstrap multi-select。我在编辑表单中预选值时遇到问题。下面是我用过的js代码:
<script>
$(document).ready(function() {
$('#tincludeds').multiselect({
includeSelectAllOption: true,
selectAllJustVisible: false,
enableFiltering: true,
numberDisplayed: 1,
maxHeight: 600,
buttonWidth: '400px',
select: {!! json_encode($tour->tIncludeds()->allRelatedIds()) !!}
});
});
</script>
但是脚本不工作。有什么我在这里错过的吗?下面是{{ dd(json_encode($tour->tIncludeds()->allRelatedIds())) }}的输出
我认为多选字段的html代码:
<div class="form-group">
<label for="tincluded">Includeds</label>
<select class="form-control" id="tincludeds" multiple="multiple" name="tincludeds[]" class="tincluded">
@foreach($tincludeds as $included)
<option value="{{ $included->id }}">{{ $included->name }}</option>t
@endforeach
</select>
@if ($errors->has('tincludeds'))
<span class="help-block">{{$errors->first('tincludeds')}}</span>
@endif
</div>
【问题讨论】:
-
你的json一定有错误
-
json_encode($tour->tExcludeds()->allRelatedIds())是正确的我已经用 dump and diedd()方法检查了它。 -
能否请您显示您的多选下拉菜单的 HTML/Laravel 代码?
-
能否附上 allRelatedIds 函数的输出?
-
也许我遗漏了一些东西,但我没有在他们的手册中看到多选插件的“选择”参数。
标签: javascript php jquery twitter-bootstrap laravel