- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
在 vue.js 中如何一个 filterBy 多个属性?
考虑以下数据结构。
new Vue({
el: body,
data: {
items: [
{name: 'thing1', age: 5, properties: [
{ name: 'color', value: 'black'},
{ name: 'weight', value: 3}
]},
{name: 'thing2', age: 3, properties: [
{ name: 'length', value: 4},
{ name: 'weight', value: 4}
]},
{name: 'thing3', age: 9, properties: [
{ name: 'color', value: 'black'},
{ name: 'length', value: 20}
]}
],
property: ''
}
});
现在,可以轻松地通过单个属性进行过滤,如下所示:
<input v-model="property" />
<div v-for="item in items | filterBy property in 'properties'">
{{ item.name }}
</div>
但是,如果我想通过多个属性进行搜索。
例如为了得到 thing3
,我试过了,但是,当然,这行不通。
property: ['black', 20]
我需要实现某种动态 filterBy 链接吗?我不知道会有多少属性。
实现此目的的粗略方法是为当前项数组中的每个不同属性创建 filterBy,并将其中大部分保留为空。像这样。
new Vue({
el: body,
data: {
items: [],
property1: '',
property2: '',
property3: '',
...
propertyN: ''
}
});
还有这个:
<div v-for="item in items | filterBy property1 in 'properties'|
filterBy property2 in 'properties'|
filterBy property3 in 'properties'|
...
filterBy propertyN in 'properties'">
{{ item.name }}
</div>
但这样做感觉不对。
最佳答案
似乎自定义函数是唯一可行的选择。
filters: {
myProperty: function(items, properties = this.properties) {
if (!properties || properties.length === 0) {
return items;
}
return this.recursiveFilter(items, propeties, 0);
}
},
methods: {
recursiveFilter: function(items, properties, currentPosition) {
if (currentPosition+1 > properties.length)
return items;
var new_items;
new_items = items.filter(function(item) {
for (row of item.properties) {
if (row.value == properties[currentPosition])
return true;
}
});
return this.recursiveFilter(new_items, properties, currentPosition+1);
}
}
关于filter - Vue.js filterBy 数组作为 searchText,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37431062/
我在我的 robotium 测试用例中使用 solo.searchText 函数。我将文本作为“$ testdata”传递以进行搜索。但即使屏幕上有文字,它也不会检测到文字。在使用 solo.sear
好的,我会尽力解释这一点。在 Google 的 AppMaker 中,我在主页中放置了一个搜索栏,并且我几乎完全按照 :SearchText 复制了合作伙伴管理。唯一的区别是在我的服务器端代码中我将其
我有一个奇怪的情况:在屏幕上,我可以单击以下字符串:“1 年基本许可证 ($15.00)” 但是下面的代码让我有些头疼:assertTrue(solo.searchText("1 年基本许可 ($15
我正在使用 robotium 来测试一个 android 项目。我有一个测试用例,我需要在其中测试一条由特殊字符组成的消息是否正确发布。所以我创建了一个由特殊字符组成的常量: public stati
现在我正在使用以下内容 let data = ["New York, NY", "Los Angeles, CA" . . .] var filteredData: [String]! filtere
我尝试使用 |filter 过滤数据在 ng-repeat 指令中。 ng-repeat="item in transactions |filter:searchText" 交易 是包含数据的数组,
我正在使用此代码在我的表格 View 中进行搜索: for (Actor *actorz in arr) { NSComparisonResult result = [actorz.
我正在使用此代码在我的表格 View 中进行搜索: for (Actor *actorz in arr) { NSComparisonResult result = [actorz.
在 vue.js 中如何一个 filterBy 多个属性? 考虑以下数据结构。 new Vue({ el: body, data: { items: [ {name: 'thi
我在使用 Robotium 的 searchText() 函数时遇到问题。 我正在搜索这个字符串: Service Activation Wizard (Step 2) 我在字符串 xml 中定义了它
我无法将默认值设置为 ng-model="searchText"。这是我正在使用的代码 谁能帮我解决这个问题? 最佳答案 第一个解决方案:是简单地在 Controller 中初始化 searchTe
这不是一个问题,而是我对在互联网上找不到解决方案的问题的回答。 我在清除 MVVM Silverlight 应用程序中的 SearchText 时遇到问题。我可以清除 SelectedItem 和 T
我已经搜索了几个小时,但看不到解决方案...我正在使用输入到 UISearchBar 中的文本来过滤自定义对象数组,以更改下面表格 View 中的数据。经过一番调试后,我找到了问题的根源: func
我正在尝试断言文本“abcd:移至历史记录”。所以我的代码是这样的: assertTrue("消息未显示",solo.searchText("abcd : 移至历史记录")); 虽然屏幕上显示消息“a
我们最近从 Protractor 4.0.14 升级到 5.3.0,但遇到错误。我们的测试正在做类似的事情: element.all(by.css('some locator')).all(by.cs
我使用 angular.js (ng-model="searchText") 创建了一个可通过输入进行搜索的列表。单击列表元素,您可以使用 {{selected | JSON}}。单击列表项时,我想将
我是一名优秀的程序员,十分优秀!