0
我使用vueJS来显示相互依赖的选择。默认值选择不工作在vuejs
我有3种型号:联盟 - 协会 - 俱乐部
我的问题是我无法选择的关联Ÿ俱乐部选择默认值(在联邦,它的工作原理...)
这里我的看法
<select name="federation_id" v-model="federationSelected" id="federation_id" class="form-control" @change="getAssociations(federationSelected)">
<option v-for="federation in federations" v-bind:value="federation.value" selected="@{{ federationId==federation.value }}">@{{ federation.text }}</option>
</select>
<div class="form-group">
{!! Form::label('association_id', trans_choice('core.association',1),['class' => 'text-bold']) !!}
<select name="association_id" v-model="associationSelected"
class="form-control" @change="getClubs(associationSelected)">
<option value="1"
v-if="associations!=null && associations.length==0 && federationSelected!=0">{{ trans('core.no_association_available') }}</option>
<option v-for="association in associations" v-bind:value="association.value"
selected="@{{ associationId==association.value }}">
@{{ association.text }}
</option>
</select>
</div>
这是我的脚本。
let Vue = require('vue');
let vm = new Vue({
el: 'body',
data: {
federations: [],
federationSelected: federationId,
associations: [],
associationSelected: associationId,
},
computed: {},
methods: {
getFederations: function() {
var url = '/api/v1/federations';
$.getJSON(url, function (data) {
vm.federations = data;
});
this.associationSelected = 1;
},
getAssociations: function (federationSelected) {
var url = '/api/v1/federations/' + federationSelected + '/associations';
$.getJSON(url, function (data) {
vm.associations = data;
});
this.clubSelected = 1;
},
}, ready: function() {
this.getFederations();
if (this.federationSelected != 1) {
this.getAssociations(this.federationSelected);
}
},
});
我检查了值是在数据库中。
传递变量到我的剧本,我有
var federationId = "{{ (Auth::user()->federation_id != 0)? Auth::user()->federation_id : 1}}";
var associationId = "{{ (Auth::user()->association_id != 0)? Auth::user()->association_id : 1}}";
在我看来的结尾。我检查associationId给我15.
但是,当我检查VUE组分,我有:
associationSelected:1个 协会:数组[14] federationSelected: “37” 联合会:数组[47]
所以基本上,我需要将associationSelected设置为他的值。
我在php中拥有这个值,但不知道为什么我不能得到它。
对不起,应该是一个复制粘贴错误。我的代码很好:v-bind –