0
我想創建一種機制,允許用戶在他們自己的網頁中嵌入一個簡單的列表(使用UL和LI)他們的出版物。WCF數據服務HTML
數據的來源是SSRS數據庫,所以我在考慮使用WCF數據服務。但是我發現WCF數據服務只返回ATOM或JSON數據。
我吠叫錯了樹嗎?
我想創建一種機制,允許用戶在他們自己的網頁中嵌入一個簡單的列表(使用UL和LI)他們的出版物。WCF數據服務HTML
數據的來源是SSRS數據庫,所以我在考慮使用WCF數據服務。但是我發現WCF數據服務只返回ATOM或JSON數據。
我吠叫錯了樹嗎?
你爲什麼不使用返回的JSON數據和使用MustacheJs或任何其他JavaScript模板工具來顯示數據爲UL和李
下面的代碼我已經使用網頁API,是WCF的一種簡單形式數據服務。你可以使用任何返回JSON數據的東西。
鬍子模板
<script id="RoleTemplate" type="Mustache/html">
{{ #roles }}
<UL>
<Li>{{RoleID}} - {{RoleName}} ({{Description}}) </Li>
</UL>
{{ /roles }}
網絡API控制器代碼
public class SecurityController : ApiController
{
// GET api/<controller>
/// <summary>
/// Get all role details
/// </summary>
/// <returns></returns>
[HttpGet]
public List<Role> GetAllRoles()
{
myApp.Security.Services.ISecurityService objSecurity = new myApp.Security.Services.SecurityService();
return objSecurity.GetAllRole();
}
}
Ajax調用
function getAllRoles() {
$.ajax({
dataType: "json",
url: '/api/Security/GetAllRole',
success: function (data) {
data = { 'roles': data }; // formatting the data to support the mustache format
var html = Mustache.to_html($('#RoleTemplate').html(), data);
$('#tblRole').append(html);
}
});
我最近的一些項目已經使用WCF Web服務來填充HTML下拉菜單而沒有任何問題。在我們的例子中,我們一直將返回類型設置爲字符串列表(VB.net),並使用javascript讀取返回值(以數組形式顯示)爲下拉列表創建新選項。這是毫無疑問的,但期望用戶知道足夠的JavaScript來完成Web服務調用並填充列表可能有點多。如果你提供的代碼以及我不認爲會有任何問題。 – StMotorSpark