在Magento管理面板中的目录产品页面中动态设置选择选项 [英] Set select options dynamically in catalog product page in Magento Admin panel

查看:63
本文介绍了在Magento管理面板中的目录产品页面中动态设置选择选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据其他选择属性,需要在选择服装中具有一组动态值.

Need to have a dynamic set of values in an select attibute, depending upon another select attribute.

例如将会有两个下拉菜单属性:1.父下拉菜单,2.子下拉菜单

e.g. there will be two dropdown attributes 1. parent dropdown, 2. child dropdown

如果在父级下拉列表中选择了"A",则下拉列表中将显示"Air","Apple","Ant".

if "A" is selected in parent dropdown then "Air","Apple","Ant" will be shown in dropdown.

如果在父属性中选择了"B",则将显示球",框",基".

if "B" is selected in parent attribute then "Ball", "Box", "Base" will be shown.

因此,基本上,子下拉列表的值将取决于父下拉列表的选定值.

So basically values of child dropdown will be depended upon the selected value of parent dropdown.

我想使其动态化,因为可以将选项保存在属性下,并且这些值将显示在目录产品编辑"页面中.

I want to make it dynamic as options can be saved under attributes and those values are to shown in Catalog Product Edit page.

谢谢.

推荐答案

如果您在JS的对象或数组的选择框中包含数据,请尝试以下代码,然后可以轻松过滤掉它并将其附加到选择框 这是演示 DEMO

try the below code if you have data inside select box in object or array in JS then you can filter it out easily and append it to select box Here's Demo DEMO

var data = {
  "A": ["Air", "Apple", "Ant"],
  "B": ["Water", "Mango", "Fly"]
}

jQuery('#parent').on('change', function() {
  var tempData = data[this.value];
  var selectChild = jQuery('#child');
  jQuery('option', selectChild).remove();
  for (var i = 0; i < tempData.length; i++) {
    var option = new Option(tempData[i], tempData[i]);
    selectChild.append(jQuery(option));
  }

});

<select id="parent">
  <option value="">Select Parent</option>
  <option value="A">A</option>
  <option value="B">B</option>
</select>
<select id="child">
  <option value="">Select Child</option>
</select>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>

这篇关于在Magento管理面板中的目录产品页面中动态设置选择选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆