【发布时间】:2011-09-15 20:47:40
【问题描述】:
我知道有人以各种方式提出过这个问题,但我一直无法为我的问题找到明确的答案。如果 CI/JQuery/Ajax 在我的应用程序中用于 CRUD 操作,我正在使用组合。在我的创建中有多个下拉列表,它们是从数据库中填充的……每个用户选择的 ID 在保存时与新记录一起存储。当用户更新该记录时,我需要能够呈现更新页面,并填充下拉列表,但设置为所选值。非常感谢您提供的有关应用程序位置/如何设置的任何指导。以下是我正在使用的代码的 sn-ps:
JQuery:
$.ajax({
url: 'index.php/admin/getEventById/' + updateId,
dataType: 'json',
success: function( response ) {
$( '#uEventName' ).val( response.event_name );
$( '#uEventType' ).val( response.eventType_eventType_id ); /*Obviously, this would work fine if I was setting the value of a textbox but this is the ID# of the value I want to have my dropdown default to */
我的观点:
<p>
<label for="uEventName">Event Name:</label>
<input type="text" id="uEventName" name="uEventName" />
</p>
<p>
<label for="uEventType">Event Type:</label> <!--I'm populating the dropdown with all values, but need it to be set to value as obtained above (via the response) -->
<?php
$eventtype_options = array();
foreach($eventtypes as $eventtype){
$eventtype_options[$eventtype->eventtype_id]=$eventtype->event_type;
}
echo "<td>" . form_dropdown('uEventType', $eventtype_options) . "</td>";
?>
</p>
【问题讨论】:
标签: jquery ajax codeigniter select drop-down-menu