0
我知道這已經以各種方式提出,但我一直無法找到明確的答案來解決我的問題。如果CI/JQuery/Ajax在我的應用程序中用於CRUD操作,我正在使用組合。在我的創建中,有多個下拉列表,這些下拉列表從數據庫填充...每個用戶選擇的標識在保存時與新記錄一起存儲。當用戶更新記錄時,我需要能夠渲染更新頁面,並填入下拉列表,但設置爲選定值。任何指導,你可以提供在應用程序/我如何設置這是非常感謝。下面是我使用的代碼片段:CodeIgniter/JQuery/Ajax:根據之前選擇的值設置下拉列表
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>
goog下午@jpea,你能更詳細的答案。 該鏈接不起作用了。 – 2016-09-27 19:42:23