Mustache JS Template with JSON Collection

后端 未结 3 1896
眼角桃花
眼角桃花 2020-12-21 15:43

Hi this is my first attempt to use MustacheJS with a JSON webservice in .net

Currently I am struggling I can\'t seem to find what I am doing wrong setting this basic

3条回答
  •  时光说笑
    2020-12-21 16:48

    The line data = { 'roles': data }; is the most crucial. Its attaching the key to the data returned by web api or any other source of data like pagemethods or web service

    $.ajax({
            dataType: "json",
            url: '/api/TestApi/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);
    
            }
        });
    

    Few of my articles on the MustacheJs can be found here

    INLINE FILTER FOR BASIC GRID USING MUSTACHEJS http://www.techguides.in/add-inline-filter-to-basic-grid-using-mustache/

    Master Details Grid on Demand data loading : Using Mustache.JS http://www.techguides.in/master-details-grid-on-demand-data-loading-using-mustache-js/

    Sorting a Grid using MustacheJs http://www.techguides.in/enable-sorting-in-a-grid-bound-using-mustache-js/

提交回复
热议问题