試圖製作一個ajax驅動的,可排序的聯繫人列表。 帶有3種替代方式的菜單應該在點擊時使用更新的數據呈現新列表。返回一個php數組到jquery ajax並填充一個列表。用一些if()的
被搜索了一下週圍,但沒有帶發現了這個有什麼好的信息(從我的理解ATLEAST ..)
這是目前什麼填充我的名單。我知道,變數不錯的選擇..
<?php
if($c['ischeckedin'])
{
$checkedin='Check Out';
$checked='checkedin';}
else{
$checkedin='Check In';
$checked='';}
?>
<li id="<?php print $c['id']; ?>" class="clearfix gradient1 <?php print $checked; ?>">
<?php print $c['name']; ?>
<img src="options.png" class="options rounded3" alt="options" width="16" height="16" />
<?php if($c['ischeckedin']): ?>
<input
type="button"
class="button checkerout"
value="<?php print $checkedin; ?>"
name="<?php print $c['id']; ?>" />
<?php else: ?>
<input
type="button"
class="button checkerin"
value="<?php print $checkedin; ?>"
name="<?php print $c['id']; ?>" />
<?php endif; ?>
</li>
<?php endforeach; ?>
所以basicly它的聯繫人列表。有些被檢入,因此不同的類和按鈕。 (任何更清潔的建議都比歡迎!)
但現在我需要通過Ajax填充列表,因爲我需要能夠對其進行排序。所以我發送了一些更多的數據,並且我的php/mysql返回了一些過濾的數據。
<li>
- ID
應該是來自數據庫的ID。 class
需要區別'checkedin'和'',這取決於mysql的結果。
<input>
- class
根據mysql的結果應該是'checkerin'或'checkerout'。 name
應該是來自db的id。
問題,我該如何處理從php返回的數據 - > ajax - > print?
如何翻譯所有那些令人討厭的if(),以便我可以在已選中和未經檢查的聯繫人之間做出區別?在返回之前編輯它?
Php已經這麼做了。我只是將一個數組放到我的ajax函數中,我不知道該如何處理。我將如何預先填充列表btw? – Xavio 2011-05-20 07:58:59