【发布时间】:2018-05-11 15:46:47
【问题描述】:
当我写 $('.selectpicker').selectpicker('refresh');在控制台中它正在加载.. 我应该在哪里提供此代码?
我的 HTML 代码是
<form action="" class="form-inline" onsubmit="return false;" method="post" id="categories">
<div class="row">
<div class="col-xs-6">
<select id="lunchBegins" class="selectpicker" data-live-search="true" data-live-search-style="begins" title="Select Your City" v-model="category" name="category">
<option v-for="post in articles" v-bind:value="post.name">{{post.name}}</option>
</select>
</div>
<div class="col-xs-6">
<select id="basic" class="selectpicker show-tick form-control" v-model="subcategory" name="subcategory">
<option v-for="so in services" v-bind:value="so.name">{{so.name}}</option>
</select>
</div>
</div>
</form>
我的 vue js 脚本如下所示。我已经在 mount() 中添加了脚本,但对我来说没有任何反应。但是当我在控制台输入..下拉列表出现
<script>
categories = new Vue({
el: '#categories',
data: {
articles: [],
services: [],
category: 0,
subcategory: 0,
content: false
},
watch: {
subcategory: function(e) {
this.prefetch();
},
category: function() {
var self = this;
self.subcategory = 0;
$.ajax({
url: "https://n2s.herokuapp.com/api/post/get_all_services/",
data: {
'service': self.id
},
type: "POST",
dataType: "JSON",
success: function(e) {
console.log('Loading services');
console.log(self.category);
let categoryIdArray = self.articles.filter(x=>x.name==self.category);
console.log(categoryIdArray);
self.services = e.filter(x=>x.cat_id==categoryIdArray[0].cat_id);
console.log(self.services);
self.prefetch();
}
});
},
},
mounted: function() {
$('.selectpicker').selectpicker('refresh');
var vm = this;
$.ajax({
url: "https://n2s.herokuapp.com/api/post/get_all_category/",
method: "GET",
dataType: "JSON",
success: function(e) {
console.log(e);
vm.articles = e;
console.log(vm);
},
});
},
})
</script>
有没有办法初始化选择选择器?请帮帮我。
【问题讨论】:
-
评论不用于扩展讨论;这个对话是moved to chat。
标签: javascript html json vue.js