【发布时间】:2018-07-23 02:19:43
【问题描述】:
我之前成功使用过 List.JS,但这次我尝试将它与 Vue.JS 一起使用,从 JSON 数据中渲染列表。
我在顶部有一个按钮,点击后应该只显示 QB 位置球员。
不幸的是,我什么也没得到,所有列表项都被删除了,我在控制台中没有收到错误,所以我不确定如何诊断。
这可能与列表元素不是预渲染/静态 html 而是使用 vue.js 注入的事实有关吗?
https://jsfiddle.net/nolaandy/hw2mheem/
HTML/Vue 模板
<div id='app'>
<div class="all-players-wrapper" id="all-player-listings">
<button id="filter-qb">QB</button>
<ul class="list">
<li v-for="player in playerJSON">
<div class="player-listing">
<div class="player-left">
<div class="player-name">{{player.firstName}} {{player.lastName}}</div>
<div class="playerPosition">{{ player.Position }}</div>
</div><!-- end player-left -->
<div class="player-right">
<div class="player-grade">GRADE <span>{{player.NFLGrade}}</span></div>
</div> <!--end player-right -->
</div>
</li>
</ul>
</div>
</div>
JS
var vm = new Vue({
el: '#app',
data: {
status: 'Combine Particpants',
playerJSON: []
},
created: function () {
this.loadData();
},
methods: {
loadData: function () {
var self = this;
axios.get('https://s3-us-west-2.amazonaws.com/s.cdpn.io/500458/tiny.json').then(function (response) {
self.playerJSON = response.data
console.log(response.data);
})
.catch(function (error) {
self.status = 'An error occurred - ' + error
});
}
}
});
var options = {
valueNames: [ 'playerPosition' ]
};
var featureList = new List('all-player-listings', options);
$('#filter-qb').click(function() {
featureList.filter(function(item) {
if (item.values().playerPosition == "QB") {
return true;
} else {
return false;
}
});
return false;
});
【问题讨论】:
-
您不能以这种方式混合使用 jQuery 和 Vue。 stackoverflow.com/a/43255516/392102
-
谢谢。我将不得不考虑更多。如果我使用车把之类的东西来模板化该循环,这种分离是否也适用?
标签: javascript jquery html vue.js list.js