2013-10-16 24 views
0

我想创建一种机制,允许用户在他们自己的网页中嵌入一个简单的列表(使用UL和LI)他们的出版物。WCF数据服务HTML

数据的来源是SSRS数据库,所以我在考虑使用WCF数据服务。但是我发现WCF数据服务只返回ATOM或JSON数据。

我吠叫错了树吗?

+0

我最近的一些项目已经使用WCF Web服务来填充HTML下拉菜单而没有任何问题。在我们的例子中,我们一直将返回类型设置为字符串列表(VB.net),并使用javascript读取返回值(以数组形式显示)为下拉列表创建新选项。这是毫无疑问的,但期望用户知道足够的JavaScript来完成Web服务调用并填充列表可能有点多。如果你提供的代码以及我不认为会有任何问题。 – StMotorSpark

回答

0

你为什么不使用返回的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); 


      } 
     });