1

我正在使用 twitter 引导模式来更新联系人,但我遇到了一些问题。模态总是显示第一个联系人的信息。但是,当我在模式之外显示信息时,它会以正确的形式显示

<?php foreach($contacts as $contact):  ?>  
<?php if($school==$contact->Schools_id): ?> 
<table class="table table-bordered  table-hover">
        <tbody><br>

                <button role="button" class="btn"><?php echo anchor('contacts/delete_contact/'.$contact->Contacts_id,' <i class="icon-remove"></i>'); ?></button>
                <a href="#UpdateContact" role="button" class="btn" data-target="#UpdateContact" data-toggle="modal"><i class="icon-pencil"></i></a>
                <tr>
                    <td>Name</td>
                    <td><?php echo $contact->name. " ". $contact->last_name; ?></td>
                </tr>
                <tr>
                    <td>Title</td>
                    <td><?php echo $contact->title; ?></td>
                </tr>
                <tr>
                    <td>Phone</td>
                    <td><?php echo $contact->phone; ?> </td>
                </tr>
                <tr>
                    <td>Email</td>
                    <td><?php echo $contact->email; ?></td>
                </tr>
                <div id="UpdateContact" class="modal hide fade" role="dialog" aria-labelledby="myModalLabel" tabindex="-1" aria-hidden="true">
                    <div class="modal-header">
                        <?php $hidden = array('contact_id' => $contact->Contacts_id,
                                              'school_id' => $contact->Schools_id);
                                echo form_open_multipart('contacts/update_contact', "", $hidden);  ?>
                        <h3>Update Contact</h3>
                    </div>
                    <div class="modal-body">
                        <label for="name">First Name <span class="required">*</span></label>
                        <input id="name" type="text" name="name" maxlength="20" ] 
                               value="<?php echo set_value('name', $contact->name ); ?>"  />
                        <br><br>
                        <label for="last_name">Last Name <span class="required">*</span></label>
                        <input id="last_name" type="text" name="last_name" maxlength="20" ] 
                               value="<?php echo set_value('last_name', $contact != NULL ? $contact->last_name : " " ); ?>"  />
                        <br><br>
                        <label for="title">Title <span class="required">*</span></label>
                        <input id="title" type="text" name="title" maxlength="45" ] 
                               value="<?php echo set_value('title', $contact != NULL ? $contact->title : " " ); ?>"  />
                        <br><br>
                        <label for="phone">Phone<span class="required">*</span></label>
                        <input id="phone" type="text" name="phone" maxlength="11" ] 
                               value="<?php echo set_value('phone', $contact != NULL ? $contact->phone : " " ); ?>"  />
                        <br><br>

                        <label for="email">Email<span class="required">*</span></label>
                        <input id="email" type="text" name="email" maxlength="45" ] 
                               value="<?php echo set_value('email', $contact != NULL ? $contact->email : " " ); ?>"  />
                    </div>
                    <div class="modal-footer">

                    <?php echo form_submit( array('class' => 'btn btn-primary', 'name' =>'submit', 'value' => 'Submit')); ?>
                    <?php echo form_close(); ?> 
                    </div>
                    </div>
              </div>

        </tbody>
    </table>

            <?php endif ?>
        <?php endforeach ?>

我在这个问题Twitter bootstrap remote modal 中找到的一些解决方案每次都显示相同的内容是:

<script type="text/javascript">       
  $(document).ready( function(){
         $('#UpdateContact').on('hide', '.modal', function () {
          $(this).removeData('modal');
        });
    });  
</script>

但仍然不适合我。

4

1 回答 1

0

就像 datasage 说的那样,您的模态 DIV id 不是唯一的。将您的 DIV id 与联系人 id 连接,以使每个模式都独一无二。

<div id="UpdateContact<?php echo $contact->Contacts_id ?>"

还要确保以相同的方式链接您的 HREF

于 2013-01-30T17:54:04.163 回答