我正在定製M2中的結帐頁面,特別是我正在尝試添加到頁面的"折扣"部分.在頁面的這一部分,我需要在載入html模板後呼叫第三方javascript庫。
我已查看淘汰生命週期事件,但它们不可用, 因為它们是3.5.0,而M 2.3.1中的KO版本是3.4.2。
現在我正在考虑添加自定義繫結,並希望添加 打電话给
init
的第三方lib
方法
我的代碼大致如下:
/app/code/Company/Module/view/frontend/web/js/view/payment/discount.js
define([
'jquery',
'ko',
'uiComponent',
'Magento_Checkout/js/model/quote',
'Magento_SalesRule/js/action/set-coupon-code',
'Magento_SalesRule/js/action/cancel-coupon',
'certificateInfo',
"setCertificateInfo",
"cancelCertificateInfo",
'Magento_Checkout/js/model/error-processor',
'Magento_SalesRule/js/model/payment/discount-messages',
], function ($, ko, Component, quote, setCouponCodeAction, cancelCouponAction, certificateInfo, setCertificateInfo, cancelCertificateInfo,errorProcessor, messageContainer) {
ko.bindingHandlers.myBinding = {
init: function(element, valueAccessor, allBindingsAccessor, data, context) {
// Call third party lib here
}
}
});
/app/code/Company/Module/view/frontend/web/template/payment/discount.html
<p data-bind="myBinding: blah">
<!-- Markup that needs to have 3rd party call to work... -->
</p>
所有發生的事情都是頁面上的錯誤
[ERROR] Failed to load the "Company_Module/js/view/payment/discount" component.
我知道自己在使用自定義繫結時遇到了什麼問题,或者以不同的方式實現我的目標吗?
最新回復
- 2019-12-51 #
我认為Magento的自定義Knockout繫結是你的答案。
用法示例:
来源: https://devdocs.magento.com/guides/v2.3/ui_comp_guide/concepts/knockout-bindings.html
有用的鏈接: https://community.magento.com/t5/Magento-2-x-PwA-Theming-Layout/How-to-call-function-after-rendering-a-knockout-js-template/mp/58781#M925< / p>