Handler实现数据模板

<ul id="ulList">
<li onclick="show('{ID}‘,'{Title}')"><a href="somepage.html?id={ID}" >{Title}</a><br />
{Content}</li>
</ul>

 

$.get("Handler.ashx?n=" + Math.random(), { action: "getNews" }, function(data) {
var list = $.parseJSON(data);
var ul = $("#ulList");
var html = "";
for (var i = 0; i < list.length; i++) {
html += ul.data("tpl").format(list[i]);
}
ul.html(html);
})

$(function() {
    var ulList = $("#ulList");
    ulList.data("tpl",ulList.html()).empty();
  }

 

 

public class News
{
public int ID { get; set; }
public string Title { get; set; }
public string Content { get; set; }
}
//handler里用了上面第一个问题的解决方法
  hs.Add("getNews", delegate()
  {
    List<News> list = new List<News>()
    {
      new News(){ ID=1,Title="title1",Content="Content1"},
      new News(){ ID=2,Title="title2",Content="Content2"},
      new News(){ ID=3,Title="title3",Content="Content3"},
    };
    return jss(list);
  });

  

你可能感兴趣的:(Handler实现数据模板)