magento - 自定义修饰符中选择的默认值
问题描述
我有一个从如下定义的表单中选择的字段。如您所见,选择有两个值,是和否。我希望为此选择设置一个默认值。
"children" => [
"bc_offer_is_duration_count_fixed" => [
"arguments" => [
"data" => [
"config" => [
"dataType" => "select",
"formElement" => "select",
"visible" => "1",
"required" => "1",
"validation" => [
'required-entry' => "1"
],
"default" => null,
"label" => __('Is duration count fixed'),
"scopeLabel" => __('[GLOBAL]'),
"code" => "bc_offer_offer_durations",
"source" => "content",
"globalScope" => true,
"sortOrder" => 10,
"componentType" => "field",
"component" => "Project_OfferProducts/js/form/element/offer-is-duration-count-fixed",
'options' => [['label' => __('Yes'), 'value' => '1'], ['label' => __('No'), 'value' => '0']]
]
]
]
]
]
modifyData
它是此处定义的类的方法的一部分
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier as CatalogAbstractModifier;
abstract class AbstractModifier extends CatalogAbstractModifier
显然我已经尝试设置"default" => "Yes"
和"default" => "1"
"default" => 1
我也有一个offer-js-duration-count-fixed.js
包含该内容的文件
define([
'Magento_Ui/js/form/element/select',
'Project_OfferProducts/js/model/offer-configuration/context'
], function (Select, context) {
'use strict';
return Select.extend({
updatingDurationFromField: false,
initialize: function () {
this._super();
context.isDurationCountFixed.subscribe(function(newValue){
this.refreshInField(newValue);
}.bind(this));
this.value.subscribe(this.refreshInGrid.bind(this));
if(context.isDurationCountFixed())
{
this.value(1);
}
else
{
this.value(0);
}
return this;
},
refreshInGrid: function(){
this.updatingDurationFromField = true;
context.isDurationCountFixed(this.value());
this.updatingDurationFromField = false;
},
refreshInField: function(newValue){
if(!this.updatingDurationFromField)
{
this.value(context.isDurationCountFixed());
}
}
});});
我在 Magento 2 下。
解决方案
正是我的想法
改变这个
'options' => [['label' => __('Yes'), 'value' => '1'], ['label' => __('No'), 'value' => '0']]
至
'options' => [['label' => __('Yes'), 'value' => 1], ['label' => __('No'), 'value' => 0]]
和改变
"default" => null,
至
"default" => "1",
推荐阅读
- java - 如何在事件处理程序中“关闭”JMenu - Java
- javascript - 如何使用 requestFullscreen() 方法从全屏显示的元素中显示模态元素?
- c++ - 未知行但恒定列
- reactjs - 在没有额外渲染的情况下设置更改的依赖项的状态(有一个没有额外渲染的加载器)
- vue.js - VueJS - 在其他绑定的定义中重用道具(字段名)
- javascript - Vue.js 从名字和姓氏中获取首字母以显示在头像中
- reactjs - Npm审计问题,不断出错
- android - 使用含税模板价格时,Android Play 控制台的默认价格是否含税?
- google-cloud-platform - google signin id_token 对 GCP 功能的权限不足
- python - 函数属性的 getattr 等效项