【发布时间】:2018-09-14 21:30:35
【问题描述】:
大家好,我目前正在 PHP 中基于 Moodle 构建一个项目,我只是好奇如何能够删除数组中的某些选择选项以用于选择选项。我正在考虑使用 disabledIf 函数,但我想不出任何用例。例如,这是我的代码:
$mform->addElement('select', 'showresults', get_string("publish", "choice"), $CHOICE_SHOWRESULTS);
$mform->addElement('select', 'publish', get_string("privacy", "choice"), $CHOICE_PUBLISH);
//$mform->disabledIf('publish', 'showresults', 'eq', 0);
$CHOICE_SHOWRESULTS 和 $CHOICE_PUBLISH 都是数组。
假设$CHOICE_SHOWRESULTS 的选项是“我喜欢参加派对”和“我不喜欢参加派对”
如果我选择“我喜欢聚会”,那么我只会得到$CHOICE_PUBLISH 的一个子集
但如果我选择“我不喜欢聚会”,那么我会得到 $CHOICE_PUBLISH 中的所有元素
在这里的moodle文档中https://docs.moodle.org/dev/Form_API
我只看到 disableIf 实际上像 if 语句一样工作,但它并没有真正说明是否选择了数组中的某个元素然后显示一些结果。
所以我想在代码中这样写:
$mform->addElement('select', 'showresults', get_string("publish", "choice"), $CHOICE_SHOWRESULTS);
if ( one choice within $CHOICE_SHOWRESULTS)
$mform->addElement('select', 'publish', get_string("privacy", "choice"), SUBSET OF $CHOICE_PUBLISH);
else { //another choice of CHOICE_SHOWRESULTS
$mform->addElement('select', 'publish', get_string("privacy", "choice"), $CHOICE_PUBLISH);
}
我是 Moodle 的初学者,所以任何事情都会有所帮助:)
【问题讨论】: