Modal在显示变量时会显示变量的所有记录吗?

时间:2015-09-28 19:02:26

标签: php mysql codeigniter

我在模态中调用var MessageBodyFull,并且只想查看特定记录的消息正文,但所有记录都显示。我已经尝试将模态移动到堆栈中的不同位置,围绕php for循环,似乎没有任何工作。

添加了上下文:' LIMIT 10'将Datatable限制为10条记录,显示邮件正文的前65个字符。每条记录都有一个指向模态的链接,我希望显示完整的邮件正文,但是当前点击链接时,模态包含所有10条记录的完整邮件正文。

查看(相关代码段)

<table id="tableDataset">
   <thead>
      <tr>
         <th><i class="icon-briefcase"></i> Recipient</th>
         <th class="hidden-xs"><i class="icon-question-sign"></i> Message Body</th>
         <th><i class="icon-bookmark"></i> Date</th>
         <th><i class="icon-bell"></i> Status</th>
      </tr>
   </thead>
   <tbody>
      <?foreach($letter_feed as $feed_item): ?>
         <tr>
            <td><?=$feed_item->Recipient?></td>
            <td class="hidden-xs"><?=$feed_item->MessageBody?> <a href="#messageBodyFull" data-toggle="modal">Full Message</a></td>
            <td><?=$feed_item->Created?> </td>
            <td><?=$feed_item->StatusDescription?></td>
         </tr>
      <?endforeach?>
   </tbody>
</table>

<div class="modal fade" id="messageBodyFull" tabindex="-1" role="dialog" aria-labelledby="messageBodyFull">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">STATUS: <?=$feed_item->StatusDescription?></h4>
      </div>
      <div class="modal-body">
        <?foreach($letter_feed as $feed_item): ?>
            <?=$feed_item->MessageBodyFull?><br><br> <!-- added the breaks to help my eyes with the error -->
        <?endforeach?>
      </div>      
      <div class="modal-footer">    
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>

模型(相关代码段)

public function get_letter_feed($user_id) { 
$sql = " 
    SELECT 
    l.uuid AS Uuid, 
    ls.`statcode` AS StatusCode, 
    ls.`statname` AS StatusDescription, 
    lst.shortnotes AS Notes, 
    lp.image AS Picture,
    CONCAT(LEFT(l.messages, 65), '') AS MessageBody, 
    l.rcpnt AS Recipient, 
    lst.createdtime AS Created
FROM Letters l
JOIN LetterAT lst ON lst.letterid = l.id AND lst.deleted IS NULL
JOIN LetterST ls ON ls.id=lst.statusId
JOIN LetterIT lp ON lp.letterid = lst.letterid
WHERE 
    l.ownerId = {$this->db->escape($user_id)}
ORDER BY lst.created DESC
LIMIT 10;";
return $this->db->query($sql)->result();  
}

控制器(相关代码段)

public function get_letter_status_feed_html() {
$letter_feed = $this->Letter_model->get_letter_feed($this->user->userId);
$this->load->view('dashboard/snippet/letter_status_feed', array('letter_feed'=>$letter_feed));
}

1 个答案:

答案 0 :(得分:1)

我认为堆栈/队列的结构存在问题。

修复:将所需的变量(var MessageBodyFill = MessageBodyFull)与所选记录一起放入,并使用document.getElementById()。innerHTML将其调用到模态中。

表格

<table id="tableDataset">
 <thead>
  <tr>
     <th><i class="icon-briefcase"></i> Recipient</th>
     <th class="hidden-xs"><i class="icon-question-sign"></i> Message Body</th>
     <th><i class="icon-bookmark"></i> Date</th>
     <th><i class="icon-bell"></i> Status</th>
  </tr>
</thead>
<tbody>
  <?foreach($letter_feed as $feed_item): ?>
     <tr>
        <td><?=$feed_item->Recipient?></td>
       <!-- FIX --> <td class="hidden-xs"><?=$feed_item->MessageBody?> <a href="#messageBodyFull" class="open-MessageBodyFill btn btn-primary"  data-id="<?=$feed_item->MessageBodyFull?>" data-toggle="modal">Full Message</a></td>  
        <td><?=$feed_item->Created?> </td>
        <td><?=$feed_item->StatusDescription?></td>
     </tr>
  <?endforeach?>
 </tbody>
</table>

新/附加脚本

<script>
    $(document).on("click", ".open-MessageBodyFill", function () {
    var MessageBodyFull = $(this).data('id');
    $(".modal-body #messageBodyFull").val( MessageBodyFull );
    document.getElementById("messageBodyFull").innerHTML = MessageBodyFull;
    });
</script>

<强>模态

<div class="modal fade" id="messageBodyFull" tabindex="-1" role="dialog" aria-labelledby="messageBodyFull">
 <div class="modal-dialog" role="document">
<div class="modal-content">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
    <h4 class="modal-title" id="myModalLabel">STATUS: <?=$feed_item->StatusDescription?></h4>
  </div>
  <div class="modal-body">
     <p type="textarea" name="messageBodyFull" id="messageBodyFull" value=""/> <!-- FIX -->
  </div>      
  <div class="modal-footer">    
    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
  </div>
</div>