以下服务器端代码有效:
[OperationContract]
public IEnumerable<object> GetBooks() {
var people = new List<object>
{
new Book{ Author="Richard Preston", Title="The Hot Zone"},
new Book{ Author="Jim Norton", Title="I Hate Your Guts"}
};
return people.AsEnumerable();
}
这是客户端代码的一部分:
<table class="Template">
<thead>
<tr>
<th>Author</th>
<th>Title</th>
</tr>
</thead>
<tbody id="bookListView">
<tr>
<td>{{Author}}</td>
<td>{{Title}}</td>
</tr>
</tbody>
</table>
function pageLoad() {
$create(Sys.UI.DataView, { serviceUri: "MyService.svc", query: "GetBooks" }, {}, {}, $get("bookListView"));
}
我希望能够向客户端返回一个 DataTable,并通过简单地引用每个列的名称来填充客户端模板。那可能吗?