このページのトップへ
Filter With Multiple Options

Filter With Multiple Options

Filter a repeater with multiple options using the Selection Tags element.

中級.png

中級

17K

出版された:

February 4, 2020

酒を楽しむ少女

によって

アンカー 1
開発者を雇う

説明例

In this example we used a repeater to display some recipes, and added selection tags to filter the repeater content based on multiple options selected by site visitors. For example, visitors can choose to view only recipes that are tagged as ‘Breakfast’ and ‘Dessert’.

コード例

タブ1

.

タブ2

.

タブ3

.

このコードによる解決は複雑になる可能性がある。

どのように構築したか

コレクション 

We added a collection to store the recipe content. The collection has descriptive fields, as well as a ‘tags’ field of type ‘Tags’ that stores the recipe’s associated categories (Breakfast, Snack, etc.) The tags are used to filter the repeater’s content.

ページ要素

In our site we added the following page elements:

 

  • Repeater: To display the recipes stored in the database collection.

  • Selection tags: For visitors to choose recipe categories. Each selection tag has a value and label that correspond to a tag used in the database collection.

コード

  1. In $w.onReady(), run the setRepeatedItemsInRepeater() function to bind specific data to the repeater elements.

  2. Call the loadDataToRepeater() function to initially load the unfiltered recipe data into the repeater. 

  3. Add an onChange() event handler to the Selection Tags element. If the selection tags change, run the loadDataToRepeater() function with the selected tags as a parameter:

    1. Create a variable to hold a Wix Data query.

    2. Check whether any selection tags were chosen. If so, use a hasAll() filter to only get the data of collection items with all of the chosen tags.

    3. Resolve the query and set the result as the repeater’s data.

    4. If the query returns no results, show a ‘No Results Found’ text message.

使用したAPI

コード以外の例。

関連記事

記事リンク

開発者を雇う

Veloソリューションは強力なツールですが、自力で構築するのは困難です。経験豊富なVelo開発会社に構築をお任せください。

関連例

これは役に立ったか?

はい

|

いいえ

ご意見ありがとう!

注目アイテム

注目アイテム

インデックスページで項目を選択する機能。

中級.png

中級

Custom Store Filters

Custom Store Filters

Filter store products by name and price

中級.png

中級

Mega Search

Mega Search

Filter a repeater using multiple input components.

中級.png

上級

アンカー2
ページ下