有一个更好的办法,但你需要重写核心文件
覆盖以下文件 应用程序\代码\核心下的方法\法师\ Adminhtml \块\小工具\表\元素\ Dependence.php
public function addFieldDependence($fieldName, $fieldNameFrom, $refValues)
{
/*
if (is_array($refValues)) {
Mage::throwException('Dependency from multiple values is not implemented yet. Please fix to your widget.xml');
}
*/
$this->_depends[$fieldName][$fieldNameFrom] = $refValues;
return $this;
}
在应用程序\代码\核心\法师\ Adminhtml \块\ SYSTEM \ CONFIG \ form.php的 修改方法initFields
if ($e->depends) {
foreach ($e->depends->children() as $dependent) {
$dependentId = $section->getName() . '_' . $group->getName() . '_' . $fieldPrefix . $dependent->getName();
if ($dependent->count()) {
$dependentValue = (array) $dependent;
$dependentValue = array_values($dependentValue);
} else {
$dependentValue = (string) $dependent;
}
$this->_getDependence()
->addFieldMap($id, $id)
->addFieldMap($dependentId, $dependentId)
->addFieldDependence($id, $dependentId, $dependentValue);
}
}
修改JavaScript文件JS \法师\ adminhtml \ form.js
trackChange : function(e, idTo, valuesFrom)
{
// define whether the target should show up
var shouldShowUp = true;
for (var idFrom in valuesFrom) {
if (valuesFrom.hasOwnProperty(idFrom)) {
if (typeof(valuesFrom[idFrom])=="object") {
shouldShowUp = false;
for(var idVal in valuesFrom[idFrom]) {
if (valuesFrom[idFrom].hasOwnProperty(idVal)) {
if (typeof(idVal)!="undefined" && ($(idFrom).value == valuesFrom[idFrom][idVal])) {
shouldShowUp = true;
}
}
}
} else if (typeof(valuesFrom[idFrom])=="string") {
if ($(idFrom).value != valuesFrom[idFrom]) {
shouldShowUp = false;
}
}
}
/*
if ($(idFrom).value != valuesFrom[idFrom]) {
shouldShowUp = false;
}
*/
}
// toggle target row
if (shouldShowUp) {
$(idTo).up(this._config.levels_up).select('input', 'select', 'td').each(function (item) {
if (!item.type || item.type != 'hidden') { // don't touch hidden inputs, bc they may have custom logic
item.disabled = false;
}
});
$(idTo).up(this._config.levels_up).show();
} else {
$(idTo).up(this._config.levels_up).select('input', 'select', 'td').each(function (item){
if (!item.type || item.type != 'hidden') { // don't touch hidden inputs, bc they may have custom logic
item.disabled = true;
}
});
$(idTo).up(this._config.levels_up).hide();
}
}
用于多值依赖以下语法上的XML
<depends>
<field1>
<val1>text</val1>
<val2>radio</val2>
</field1>
</depends>
+1所申报的确切符号分开肮脏的“评论代码”诡计。 – epeleg 2011-01-31 20:05:19
然而,看起来我没有妥善处理我Q上的逃跑,并且两个地方都看不到。所以我现在修复了问题,并且我希望有人能够利用标签提供帮助。请注意,“注释中的代码”技巧使翻译注释变得困难(如果您将此代码置于实际上没有真正意见的字段的注释中,这可能不是问题)。 –
epeleg
2011-01-31 20:09:41