如何使用数字 RefinementList 设置允许的距离?
How to use the numericRefinementList to set allowed distances?
我希望能够使用numericRefinementList 来让用户选择一个item 离自己的距离可以吗?这将使用 IP 地理位置功能或从浏览器输入地理位置(如果可用)。
- 不到50公里
- 50 - 100 公里
- 100 - 150 公里
- 150公里以上
https://community.algolia.com/instantsearch.js/documentation/#numericrefinementlist
不幸的是,这不是您可以使用 numericRefinementList 执行的操作,但您可以构建自定义小部件设置 aroundRadius
,具体取决于您单击的 link:
function radiusList(options) {
if (!options.container) {
throw new Error('radiusList: usage: radiusList({container, ...})');
}
var $container = $(options.container);
if ($container.length === 0) {
throw new Error('radiusList: cannot select \'' + options.container + '\'');
}
return {
init: function(args) {
// event delegation: set the aroundRadius of the underlying link
$(document).on('click', '.radius-link', function(e) {
e.preventDefault();
args.helper.setQueryParameter('aroundRadius', +$(this).data('radius'));
args.helper.search();
});
},
render: function(args) {
// FIXME: display the list of radius links
var html = '<ul>';
html += '<li><a href="#" data-radius="100000" class="radius-link">< 100km</a></li>';
html += '</ul>';
$container.html(html);
}
};
}
然后将其用于:
search.addWidget(radiusList({container: '#my-radius-list'}));
我希望能够使用numericRefinementList 来让用户选择一个item 离自己的距离可以吗?这将使用 IP 地理位置功能或从浏览器输入地理位置(如果可用)。
- 不到50公里
- 50 - 100 公里
- 100 - 150 公里
- 150公里以上
https://community.algolia.com/instantsearch.js/documentation/#numericrefinementlist
不幸的是,这不是您可以使用 numericRefinementList 执行的操作,但您可以构建自定义小部件设置 aroundRadius
,具体取决于您单击的 link:
function radiusList(options) {
if (!options.container) {
throw new Error('radiusList: usage: radiusList({container, ...})');
}
var $container = $(options.container);
if ($container.length === 0) {
throw new Error('radiusList: cannot select \'' + options.container + '\'');
}
return {
init: function(args) {
// event delegation: set the aroundRadius of the underlying link
$(document).on('click', '.radius-link', function(e) {
e.preventDefault();
args.helper.setQueryParameter('aroundRadius', +$(this).data('radius'));
args.helper.search();
});
},
render: function(args) {
// FIXME: display the list of radius links
var html = '<ul>';
html += '<li><a href="#" data-radius="100000" class="radius-link">< 100km</a></li>';
html += '</ul>';
$container.html(html);
}
};
}
然后将其用于:
search.addWidget(radiusList({container: '#my-radius-list'}));