3

我有一个功能,正在构建一个像这样的 url:

http://localhost/listings?q=&idx=content_index&p=0&dFR[objectID][0]=97&dFR[objectID][1]=96

它创建了一个 facetFilters: [["objectID:97","objectID:96"]]"}。我有一个 clear All 功能也可以清除所有过滤器:

        search.addWidget(
        instantsearch.widgets.clearAll({
            container: '#clearAll',
            templates: {
                link: '<i class="icon icon-undo2"></i>'
            },
            autoHideContainer: false,
            clearsQuery: true
        })
    );

这工作得很好,也清除了上面的过滤器。但是问题是在开始路由时出现的。通过路由,

http://localhost/listings?q=&idx=content_index&p=0&dFR%5Bgenres.name%5D%5B0%5D=Comedy

变成 :

http://localhost/listings?genres=Comedy

已对上述内容进行了以下更改:

routing: {
stateMapping: {
    stateToRoute(uiState) {

        return {
            query: uiState.query,
            // we use the character ~ as it is one that is rarely present in data and renders well in urls
            genres:
            uiState.refinementList &&
            uiState.refinementList['genres.name'] &&
            uiState.refinementList['genres.name'].join('~'),
            page: uiState.page
        };
    },
    routeToState(routeState) {

        return {
            query: routeState.query,
            refinementList: {
                'genres.name': routeState.genres && routeState.genres.split('~'),
            },
            page: routeState.page
        };
    }
}

},

必须为 objectID 实现相同的功能。怎么做?

4

0 回答 0