0

(编辑以提供更清晰的示例)我有文档->节->变量的cakephp模型结构

在一个表单中,我希望能够列出所有变量,但嵌套在文档和节级别中。那一点没问题。

我想要变量级别的每个项目旁边的复选框 - 以允许选择变量。

I want a checkbox at sectionlevel, that when selected will select all the checkboxes for the variables in that section.

我想要在文档级别的复选框,以便选择该文档的变量(即所有部分)。

为了方便起见,我这样命名了复选框(好吧,我已经设置了 ID)(伪代码):

document level: id = Document id
section level id = Document id_Section id
variable level id = Document id_Section id_Variable_id

我希望如果我选择部分级别复选框,我可以通过在可变级别复选框的所有 id 开头使用 Document id_Section_id 存根来设置该部分的所有可变级别复选框......但也许我正在抓住稻草?

以下是级别中的复选框示例:(为布局道歉)

    <?php
//Document level
//all of this within a ForEach loop for documents
echo "<table>";
echo "<tr><td>Collection dates</td><td>".$project_document['data_collection_dates']."</td>";
echo "<td>Select (toggle) all variables"
        .$this->Form->checkbox($project_document['id'], // note that this sets the chkbox id to the value of the current document id
                            array('hiddenField' => false,'onclick'=> 'SelectSection(this,this.name,this.checked);'))
                            ."</td></tr>";
echo "</table>";

foreach ($project_document['ProjectDocumentSection'] as $project_document_section): 
    echo "<h4>" .  $project_document_section['title']. "</h4>";
    echo "<table>";
    echo "<tr><td>Collection Method</td><td>" . $project_document_section['method']. "</td></tr>";
    echo "<tr><td>Collection objective</td><td>" . $project_document_section['objective']. "</td>";
    echo "<td>Select (toggle) all section variables"
            .$this->Form->checkbox($project_document['id']
                ."_".$project_document_section['id'] // and here the chkbox id is set to combination of document id and section is (using _ as separator)
                , array('hiddenField' => false))."</td></tr>";
    echo "</table>";
        echo "<table><tr><th>Full text</th><th>Type</th><th>Format</th><th>Codeset</th></tr>" ; // header for variable table
        foreach ($project_document_section['ProjectDocumentSectionVariable'] as $project_document_section_var):
            echo"<tr><td>".$project_document_section_var['variable_type'] 
                            ."</td><td>".$project_document_section_var['variable_format'] 
                            ."</td><td>";
            echo "<td>".$this->Form->checkbox($project_document['id']
                    ."_".$project_document_section['id']
                        ."_".$project_document_section_var['id'], array('hiddenField' => false))."</td></tr>";
        endforeach;
        echo "</table>";

endforeach;
// and later endforeach for the document itself

?>

当渲染时,它可能看起来像这样;

<td>Select (toggle) all variables
<input type="checkbox" name="data[Project][11]"  onclick="SelectSection(this,this.name,this.checked);" value="1" id="Project11"/>
// note that checkbox id and name include ref to document id (11)
</td></tr>

<h4>Details of Health Workers at Facility</h4>

<table>
 <tr><td>Collection Method</td><td>FW completed evaluation on paper</td></tr>
<tr><td>Collection objective</td><td>blah blah blah blah</td>
<td>Select (toggle) all section variables
<input type="checkbox" name="data[Project][11_24]"  value="1" id="Project1124"/></td></tr>
// note that checkbox id and name include ref to document id (11) and section id (24)
</table>
<table>
<tr><th>Full text</th><th>Type</th><th>Format</th><th>Codeset</th></tr>
<tr><td>Site</td><td>Categorical</td><td>Quantative</td>
<td><input type="checkbox" name="data[Project][11_24_402]"  value="1" id="Project1124402"/></td></tr>
// note that checkbox id and name include ref to document id (11), section id (24) and variable id (402)
<tr><td>Facility</td><td>Categorical</td><td>Quantative</td>
<td><input type="checkbox" name="data[Project][11_24_403]"  value="1" id="Project1124403"/></td></tr>
<tr><td>Name</td><td>Text</td><td>Quantative</td>
<td><input type="checkbox" name="data[Project][11_24_404]"  value="1" id="Project1124404"/></td></tr>
<tr><td>Position of Health Worker</td><td>Text</td><td>Quantative</td>
<td><input type="checkbox" name="data[Project][11_24_405]"  value="1" id="Project1124405"/></td></tr>
<tr><td>Description</td><td>Text</td><td>Quantative</td>
<td><input type="checkbox" name="data[Project][11_24_406]"  value="1" id="Project1124406"/></td></tr>
<tr><td>Interviewer Code</td><td>Categorical</td><td>Quantative</td>
<td><input type="checkbox" name="data[Project][11_24_407]"  value="1" id="Project1124407"/></td></tr>
<tr><td>Date of Facility Visit </td><td>Date</td><td>Quantative</td>
<td><input type="checkbox" name="data[Project][11_24_408]"  value="1" id="Project1124408"/></td></tr>
</table>

有人对如何解决这个问题有任何建议吗?我敢肯定有不止一种方法可以杀死这只鸟..

谢谢

保罗

4

1 回答 1

0

如果我理解您的问题,只需使用FormHelper创建您的复选框 - 他们会将模型包含在他们的 中id,然后您可以单击使用 Javascript(jQuery 使其变得容易)修改包含“_variable”或“_section” ...ETC

于 2013-06-10T13:48:00.613 回答