javascript - jsrender 模板不会渲染,有什么想法吗?

标签 javascript jquery jsrender

谁能告诉我为什么这个模板无法渲染?

我像这样渲染它:

 var v = jQuery.url().param("id");
        jQuery.ajax({
            post: "POST",
            url: "svc.asmx/FetchNewsDetail",
            dataType: "text",
            contentType: "application/json; charset=utf-8",
            data: { 'id': v },
            success: function (data) {

                jQuery("#blog").append(jQuery("#newsSingleTemplate").render(data));
            }
        });

这是我通过 Web 方法(asp.net、asmx)收到的 json 字符串:

{"newsDetailId":1,"newsId":1,"newsItemTitle":"Make Your Reservations Before It\u0027s Too Late","newsItemDate":"\/Date(1400652000000)\/","newsItemBannerUrl":"img/news/bass_single_news.jpg","newsItemBannerAlt":"BASS Divisional","newsItemText":"Join us at the Noxon Reservoir in Trout Creek, Mont., for the 2014 B.A.S.S. Nation Western Divisional. This fishery is in the northwest corner of Montana, very close to Idaho and only a 2-hour drive to Canada. Montana has hosted B.A.S.S. Nation divisionals, but it has not hosted other levels of B.A.S.S. tournaments. Competitors will vie for the Western title May 21-23.","newsItemQuote":"I think what I like most about B.A.S.S. Nation divisionals is the opportunity to go to places that you don\u0027t often think of as well-known tournament destinations, such as Noxon in Montana and Lake Monroe in Indiana\"- Jon Stewart, director of the B.A.S.S. Nation"}{"d":null}

这是我的模板

            <script id="newsSingleTemplate" type="text/x-jsrender">
            <article>
                <section class="first-column">
                    <header>
                        <h2>{{:newsItemTitle}}</h2>
                    </header>
                    <div class="date">
                        {{:newsItemDate}}
                    </div>
                    <p>
                        <img src="{{url:newsItemBannerUrl}}" width="670" height="300" alt="{{:newsItemBannerAlt}}" />
                        <br />{{:newsItemText}}</p>
                    <div id="slogan">
                        <h1>{{:newsItemQuote}}</h1>
                    </div>
                </section>
            </article>
            </script>

谢谢你的帮助!

最佳答案

已成功测试 a fiddle 。你的问题表述得不是很清楚。究竟是什么不起作用?您的模板适用于哪种上下文?您使用什么数据结构?

var template = $.templates("#newsSingleTemplate");

template.link("#result", data);

关于javascript - jsrender 模板不会渲染,有什么想法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23352862/

相关文章:

javascript - 在 JavaScript 中递归构建树

Javascript 同步控制台提示符

javascript - 在弹出窗口中使用 cookie 后弹出窗口不起作用

javascript - 使用 JsRender 的简单 for 循环

json - 是否可以在 JSRender 中使用增量变量 i 进行 for 循环?

javascript - rxjs中 `expand`是什么意思

javascript - 如何在 JavaScript 中解析 excel 文件?

jquery - jqGrid动态列绑定(bind)

javascript - 使用 jquery 开始旋转时如何保持克隆元素的旋转位置

css - JsViews css-tag 中的逻辑