0

私は、ユーザーが出版物の簡単なリスト (UL と LI を使用) を自分の Web ページに埋め込むことができるメカニズムを作成したいと考えています。

データのソースは SSRS データベースなので、WCF Data Service の使用を考えていました。しかし、WCF データ サービスは ATOM または JSON データしか返さないことがわかりました。

私は間違った木を吠えていますか?

4

1 に答える 1

0

返された JSON データを使用し、MustacheJs またはその他の JavaScript テンプレート ツールを使用して、データを UL および Li として表示してみませんか?

以下のコードは、単純な形式の wcf データ サービスである Web API を使用しています。JSON データを返すものは何でも使用できます。

口ひげのテンプレート

<script id="RoleTemplate" type="Mustache/html">
  {{ #roles }}
         <UL>
              <Li>{{RoleID}} - {{RoleName}} ({{Description}}) </Li>
         </UL>    
{{ /roles }}

Web 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);


             }
         });
于 2013-10-22T03:59:28.570 に答える