0

所以在 CakePHP 中,我设置了一些选项。在选项中,我试图让类属性看起来像这样:

class='application_level_#'

# 来自 $app_list 中的数据。$app_list 如下所示:

Array ( 
[0] => Array ( [Nature] => 5 ),
[1] => Array ( [Math] => 0 ), 
[2] => Array ( [Art] => 0 ) )

元素对应每所学校,名称为键,值为应用等级。这个值是 # 应该是什么。我让用户选择一个触发功能并检索等级值的等级。然后在我的函数中,我将用于显示学校选择的 css 更改为阻止(从无),然后使用 Javascript 将带有 class='application_level_#' 的每个学校广播元素更改为 display: block (from none)。

我的 school_form_element.ctp:

<!-- Schools Element -->
<div id="school_selection"> 
    <?php
        $schools = $this->requestAction('/schools/index');
        $app_list = $this->requestAction('/schools/app_list');

        print_r($app_list);

        //Sets up a radio button. 
        echo $this->Form->input('school_selection', 
            array('type' => 'radio', 'options' => $schools, 'onclick' => 'showStudentInfoBox()', 'class' => '**app_list[id]** how to build this?'));
    ?>
</div>
<!-- End Schools Element -->

Javascript (form.js)

function showSchools(){
    var grade_radio = document.getElementsByName('data[StudentApplicationForms][grade_selection]');
    var application_level = null;

    for(var i=0, length = grade_radio.length; i < length; i++){
        if(grade_radio[i].checked){
            application_level = grade_radio[i].value;
            break;
        }
    }

    var school_options = document.getElementsByClassName('application_level_', application_level);
    school_options.style.display = 'block';

}

编辑:我应该看看 CakePHP 的 JS 助手吗?

4

0 回答 0