6 とその値 (空かどうか) を含むリストを作成し、li
それを既存の に追加する必要がありますli
。
これらの結果が SQL クエリから返されます。
id_news title category order
------- -------- -------- -----
3 Alex... 12 1
12415 Obama... 3 3
そのデータを使用して、順番に並べたorder
リストを作成する必要があります。つまり、リストは次のようになります。
<ul>
<li data-order="1"> Alex... </li>
<li data-order="2"> No featured news here, click to add </li>
<li data-order="3"> Obama... </li>
<li data-order="4"> No featured news here, click to add </li>
<li data-order="5"> No featured news here, click to add </li>
<li data-order="6"> No featured news here, click to add </li>
</ul>
だから、私の質問は次のとおりです。
- 定義済みのリストを用意して、そこにデータを追加する必要がありますか?
- または、リストの作成中にそれを行う必要がありますか? もしそうなら、どのように?
私が今持っているjQueryコード:
var sublist = '<ul id="order_list"> <h3> Order list: </h3>';
$.each(data, function(index, value) {
sublist += '<li data-target="'+value['id_news']+'">'+value['headline']+'</li>';
});
sublist += '</ul>';
list.append(sublist);