【发布时间】:2015-05-18 14:31:07
【问题描述】:
我正在尝试在我的商店中实施 Shopify 的链接产品选项(遵循此 tutorial),它们似乎在产品页面上运行良好,但在我的索引和集合页面。
我在 Safari 中遇到以下错误:
TypeError: undefined is not an object (evaluating 'availableOptions.length')
引用了这段代码:
var initialValue = selector.val();
selector.empty();
var availableOptions = Shopify.optionsMap[key];
for (var i=0; i<availableOptions.length; i++) {
var option = availableOptions[i];
var newOption = jQuery('<option></option>').val(option).html(option);
selector.append(newOption);
}
如果有人对为什么会这样有任何建议,我将不胜感激。我不擅长 JS,所以在这个方面很挣扎!
更新:
我很确定这部分正在定义“键” - 如果键未定义是否意味着它无法找到 .single-option-selector?
switch (selectorIndex) {
case 0:
var key = 'root';
var selector = jQuery('.single-option-selector:eq(0)');
break;
case 1:
var key = jQuery('.single-option-selector:eq(0)').val();
var selector = jQuery('.single-option-selector:eq(1)');
break;
case 2:
var key = jQuery('.single-option-selector:eq(0)').val();
key += ' / ' + jQuery('.single-option-selector:eq(1)').val();
var selector = jQuery('.single-option-selector:eq(2)');
}
【问题讨论】:
标签: javascript jquery shopify