I want to filter data in an acordeon which is has 4 parts. My code's sample is below (I have cleared acordeon codes and some different parts in my code)
我想在一个有4个部分的acordeon中过滤数据。我的代码示例如下(我已经清除了代码中的acordeon代码和一些不同的部分)
<input type="text" ng-model="searchText" placeholder="Filter">
<dl>
<dt ng-repeat-start="mainCategory in mainCategories | filter:searchText" >
{{mainCategory.Name}}
</dt>
<dd ng-repeat-end="">
<dl>
<dt ng-repeat-start="subCategory in subCategories[mainCategory.ID] | filter:searchText" >
{{subCategory.Name}}
</dt>
<dd ng-repeat-end="">
<dl>
<dt ng-repeat-start="lesson in subCategoryLessons[subCategory.ID] | filter:searchText" >
{{lesson.Name}}
</dt>
<dd ng-repeat-end="">
<dl>
<dt ng-repeat-start="subLesson in subLessons[lesson.ID] | filter:searchText">
{{subLesson.Header}}
</dt>
<dd ng-repeat-end="">
{{subLesson.Content}}
</dd>
</dl>
</dd>
</dl>
</dd>
</dl>
</dd>
</dl>
SubCategory, Lesson and SubLesson datas are come from another service and they are saving in different arrays.
SubCategory,Lesson和SubLesson数据来自另一个服务,它们保存在不同的数组中。
I want to filter datas in this view include all data. But if I write some word in the subLesson part (the lowest category), I have to see parent parts(html elements) to reach sublesson data via opening acordeon.
我想在此视图中过滤数据包括所有数据。但是如果我在subLesson部分(最低类别)中写了一些单词,我必须看到父部分(html元素)通过打开acordeon来获取sublesson数据。
Can I create a filter like this? All data will come from a web service with JSON format. I have to consider ajax latency.
我可以创建这样的过滤器吗?所有数据都来自具有JSON格式的Web服务。我必须考虑ajax延迟。
1 个解决方案
#1
3
AFAIK, filter
pipe will search in all properties of your object, with an infinite depth.
AFAIK,过滤管道将搜索对象的所有属性,具有无限深度。
Hence you can apply the filter to the first collection, mainCategories
, in the first ng-repeat, if and only if you have all your subCategories
contained in your mainCategories
object, and so on.
因此,当且仅当您的mainCategories对象中包含所有子类别时,您才可以将过滤器应用于第一个ng-repeat中的第一个集合mainCategories,依此类推。
For instance, your data will look like this :
例如,您的数据将如下所示:
mainCategories = [{
subCategories : [{
lessons : [{
subLessons : [{
...
}]
...
}]
...
}]
...
}]
And you'll use it like this :
你会像这样使用它:
<dt ng-repeat-start="mainCategory in mainCategories | filter:searchText" >
{{mainCategory.Name}}
</dt>
<dd ng-repeat-end="">
<dl>
<dt ng-repeat-start="subCategory in mainCategory.subCategories">
#1
3
AFAIK, filter
pipe will search in all properties of your object, with an infinite depth.
AFAIK,过滤管道将搜索对象的所有属性,具有无限深度。
Hence you can apply the filter to the first collection, mainCategories
, in the first ng-repeat, if and only if you have all your subCategories
contained in your mainCategories
object, and so on.
因此,当且仅当您的mainCategories对象中包含所有子类别时,您才可以将过滤器应用于第一个ng-repeat中的第一个集合mainCategories,依此类推。
For instance, your data will look like this :
例如,您的数据将如下所示:
mainCategories = [{
subCategories : [{
lessons : [{
subLessons : [{
...
}]
...
}]
...
}]
...
}]
And you'll use it like this :
你会像这样使用它:
<dt ng-repeat-start="mainCategory in mainCategories | filter:searchText" >
{{mainCategory.Name}}
</dt>
<dd ng-repeat-end="">
<dl>
<dt ng-repeat-start="subCategory in mainCategory.subCategories">