我正在尝试向我的后端组件添加一个多选列表,但我似乎无法让它工作。我已经尝试搜索 joomla 论坛并尝试了他们的建议,但它仍然不起作用。
这是我所做的:
/models/fields/categories.php
foreach ($result as $item) {
$options[] = JHtml::_('select.option', $item->id, $item->title);
};
$drawField = '';
$drawField .= '<select name="'.$this->name.'" id="'.$this->name.'" class="inputbox" size="10" multiple="multiple">';
$drawField .= JHtml::_('select.options', $options, 'value', 'text', $strVal, true);
$drawField .= '</select>';
return $drawField;
/models/forms/edit.xml
<field name="catid" type="categories" multiple="true" size="40" class="inputbox" label="COM_PRODUCTS_FORM_LBL_EDIT_CATID" description="COM_PRODUCTS_FORM_DESC_EDIT_CATID" required="true" filter="safehtml" />
/models/edit.php
protected function loadFormData()
{
$data = JFactory::getApplication()->getUserState('com_products.edit.edit.data', array());
if (empty($data)) {
$data = $this->getItem();
$data->catid = explode(',',$data->catid);
}
return $data;
}
/tables/edit.php
public function check() {
if (property_exists($this, 'ordering') && $this->id == 0) {
$this->ordering = self::getNextOrder();
}
$this->catid = implode(',',$this->catid);
return parent::check();
}
它在后端将字段 catid 保存为“Array”。然而,当我手动输入 143,148 作为字段值时,它并没有突出显示这些字段,所以显然我的内爆/爆炸不起作用..任何帮助将不胜感激!
谢谢 :)