【发布时间】:2016-05-28 16:31:10
【问题描述】:
我正在整理一个简单的图书分类应用程序,但在使用 filterBy 过滤器时遇到了一些问题。该过滤器适用于过滤non-fiction genre,但由于某种原因它不适用于fiction。我想显示书名和作者,然后在输入字段中,过滤按流派显示的书籍列表。因此,如果我在输入字段中写小说,它应该只显示小说书籍。这就是我的观点:
<div id="app">
<h1>{{title}}</h1>
<div id="input">
<input type="text" v-model="genre" placeholder="Search fiction/non-fiction">
</div>
<div id="display-books" v-for=" book in books | filterBy genre in 'genre' ">
<span>Title: {{book.title}}</span>
<span>Author: {{book.author}}</span>
</div>
</div>
这是我的app.js:
var appData = {
title: 'Book Sorter',
filters: 'Search filter',
filtertext: '* only show title if book is available',
genre: '',
books:
[
{genre: "fiction", title: "The Hobbit", author: "J.R.R Tolkien", available: false},
{genre: "non-fiction", title: "Homage to Catalonia", author: "George Orwell", available: true},
{genre: "non-fiction", title: "The Tipping Point", author: "Malcolm Gladwell", available: false},
{genre: "fiction", title: "Lord of the Flies", author: "William Golding", available: true},
{genre: "fiction", title: "The Call of the Wild", author: "Jack London", available: true}
]
}
new Vue({
el: "#app",
data: appData,
});
【问题讨论】:
标签: javascript vue.js