Magento configurable.js - separatorIndex做什么?

时间:2012-07-10 05:47:20

标签: javascript magento

我想知道以下代码的作用,因为我在类别列表视图中遇到自定义可配置选择器+ AJAX预览的问题。

    var separatorIndex = window.location.href.indexOf('#');
    if (separatorIndex != -1) {
        var paramsStr = window.location.href.substr(separatorIndex+1);
        var urlValues = paramsStr.toQueryParams();
        if (!this.values) {
            this.values = {};
        }
        for (var i in urlValues) {
            this.values[i] = urlValues[i];
        }
    }

我得到的错误是Uncaught TypeError: Cannot read property 'config' of undefined

只有在URL中有哈希值(分层导航)时才会发生这种情况。

1 个答案:

答案 0 :(得分:2)

var separatorIndex = window.location.href.indexOf('#'); // Looks for index of # in url
if (separatorIndex != -1) { // If # exists and index is set
    var paramsStr = window.location.href.substr(separatorIndex+1); // Get everything after the # in url
    var urlValues = paramsStr.toQueryParams(); // Transform to key value
    if (!this.values) { // Don't know where this comes from?
        this.values = {};
    }
    for (var i in urlValues) {
        this.values[i] = urlValues[i]; // Fill up the this.values with values from the substring after #
    }
}