npm - 如何在 BigCommerce Stencil 主题中使用 Select2
问题描述
我想在我的 BigCommerce 商店的 Stencil 主题上使用 jQuery select2 库。我该怎么做呢?
解决方案
为了在 Cornerstone 主题上完成此操作,您将按照以下步骤操作。
- 将 Select2 添加到您的 package.json
npm install select2 --save
- 将 Select2 添加到您的 webpack 配置解析/别名
select2: path.resolve(__dirname, 'node_modules/select2/dist/js/select2.min.js'),
- 在您希望使用它的地方导入库(例如 product.js)
import 'select2';
- 导入 Select2 css
@import "../../node_modules/select2/src/scss/core";
- 现在您需要调用
select2()
您希望它运行的任何字段。我通过- 创建自定义产品模板
- 创建自定义产品视图模板
dynamicComponent
为产品选项创建自定义替换- 将类添加到您希望它运行的
select2
任何元素select
$('.select2').select2();
在 product.js 中运行onReady
- 最后,您需要修复 CSS 以使 select2 正确显示。尝试
.select2 {font-size: $input-small-fontSize;}
由于这其中最棘手的部分是自定义dynamicComponent
模板,这就是我所做的
{{#if this.type "===" "Configurable_PickList_Set"}}
{{#if this.partial "===" "set-radio"}}
{{> components/products/options/set-radio this }}
{{/if}}
{{#if this.partial "===" "set-rectangle"}}
{{> components/products/options/set-rectangle this }}
{{/if}}
{{#if this.partial "===" "set-select"}}
{{> components/products/options/set-select this select2="true" }}
{{/if}}
{{else}}
{{{dynamicComponent 'components/products/options'}}}
{{/if}}
推荐阅读
- java - Java 插入排序中的错误
- python - Openpyxl xlsx 结果是附加而不是覆盖
- swift - UITextField rightView 图像和按钮?
- html - 没有填充的CSS边距不起作用
- html - 相邻元素实际上如何围绕浮动元素工作?CSS
- scala - 使用 in 子句批量更新
- ios - 当 ButtonB 被隐藏时,StackView 为 ButtonA 上浆
- php - 取回正确数量的匹配项
- vuejs2 - Bootstrap-vue b-table:如何为非活动行设置 css-Class?
- azure-active-directory - 如何使用服务用户和令牌而不是证书来管理 Azure AD?