JQuery 纯模板

发布于 2024-09-02 05:58:13 字数 3235 浏览 5 评论 0原文

我不知道出了什么问题。当我尝试仅刷新主题时它起作用,但当尝试刷新主题和页面链接时它不起作用。 IE。主题表刷新,“页面链接”消失,我认为纯粹无法到达 - 读取第二个模板节点。

顺便说一句,我测试了他们的代码,第一个消息框显示所有节点 - 包括“页面链接”节点,但第二个消息框 - 在函数中仅显示主题行。它看起来像一个错误。有人知道我该如何解决这个问题吗?

附注我用的是最新版本的pure.

谢谢。

测试代码 - pure.js 行:189

function dataselectfn(sel) {
    // ...
    m = sel.split('.');
    alert(m.toSource());
    return function (ctxt) {
        var data = ctxt.context;
        if (!data) {
            return '';
        }

        alert('in function: ' + m.toSource());
        // ...

Json:

{"topics":[{"name":"foo"}],"pagelinks":[{"Page":1},{"Page":2}]}

HTML - 纯渲染之前:

<table>
    <tbody>
        <tr>
            <td class="pagelinks">
                <a page="1" href="/Topics/IndexForAreas?page=1" class="p Page@page">1</a>
            </td>

            <td class="pagelinks">
                <a page="2" href="/Topics/IndexForAreas?page=2" class="p Page@page">2</a>
            </td>
        </tr>
    </tbody>
</table>

HTML - 纯渲染之后:

<table>
    <tbody>
        <tr>
        </tr>
    </tbody>
</table>

控制器:

    [Transaction]
    public ActionResult IndexForAreas(int? page)
    {
        TopicService topicService = new TopicService();
        PagedList<Topic> topics = topicService.GetPaged(page);
        if (Request.IsAjaxRequest())
        {
            return Json(new {
                topics = topics.Select(t => new {
                    name = t.Name,
                }),
                pagelinks = PagingHelper.AsPager(topics, 1)
            });
        }
        return View(topics);
    }

ASP.NET - 视图:

<div class="topiccontainer">
    <table>
        <%
            foreach (Topic topic in ViewData.Model)
            { %>
        <tr class="topics">
            <td>
                <%= Html.ActionLink<ForumPostsController>(ec => ec.Index(topic.Name, null), topic.Name, new { @class="name viewlink@href" })%>
            </td>
            //bla bla...
        </tr>
        <%} %>
    </table>
    <table>
        <tr>
            <% Html.Pager(Model, 1, p =>
           { %>
            <td  class="pagelinks">
                <%= Html.ActionLink<TopicsController>(c => c.IndexForAreas(p.Page), p.Page.ToString(), new { page = p.Page, @class = "Page@page" })%>
            </td>
            <% }); %>
        </tr>
    </table>
</div>

母版页:

    <% Html.RenderAction("IndexForAreas", "Topics", new { area = "" }); %>
    <script type="text/javascript">
        $.post("<%= Html.BuildUrlFromExpressionForAreas<TopicsController>(c => c.IndexForAreas(null)) %>", { page: page },
                function (data) {
                    $(".topiccontainer").autoRender(data);
                },
                "json"
        );
    </script>

I cant figure out whats wrong. Its working when i tried to refresh only topics but it doesnt works when tried to refresh topics and page-links. ie. topics table's refreshing, and 'pagelinks' disappearing, i thought pure cannot reach - read second template node.

By the way, i tested their code, first message box show up all of nodes - includes 'pagelinks' node, but second one - in function only show up topic rows. Its look like a bug. Anyone knows how can i solve this?

ps. I'm using latest version of pure.

Thanks.

Test Code - pure.js line: 189

function dataselectfn(sel) {
    // ...
    m = sel.split('.');
    alert(m.toSource());
    return function (ctxt) {
        var data = ctxt.context;
        if (!data) {
            return '';
        }

        alert('in function: ' + m.toSource());
        // ...

Json:

{"topics":[{"name":"foo"}],"pagelinks":[{"Page":1},{"Page":2}]}

HTML - before pure rendering:

<table>
    <tbody>
        <tr>
            <td class="pagelinks">
                <a page="1" href="/Topics/IndexForAreas?page=1" class="p Page@page">1</a>
            </td>

            <td class="pagelinks">
                <a page="2" href="/Topics/IndexForAreas?page=2" class="p Page@page">2</a>
            </td>
        </tr>
    </tbody>
</table>

HTML - after pure rendering:

<table>
    <tbody>
        <tr>
        </tr>
    </tbody>
</table>

Controller:

    [Transaction]
    public ActionResult IndexForAreas(int? page)
    {
        TopicService topicService = new TopicService();
        PagedList<Topic> topics = topicService.GetPaged(page);
        if (Request.IsAjaxRequest())
        {
            return Json(new {
                topics = topics.Select(t => new {
                    name = t.Name,
                }),
                pagelinks = PagingHelper.AsPager(topics, 1)
            });
        }
        return View(topics);
    }

ASP.NET - View:

<div class="topiccontainer">
    <table>
        <%
            foreach (Topic topic in ViewData.Model)
            { %>
        <tr class="topics">
            <td>
                <%= Html.ActionLink<ForumPostsController>(ec => ec.Index(topic.Name, null), topic.Name, new { @class="name viewlink@href" })%>
            </td>
            //bla bla...
        </tr>
        <%} %>
    </table>
    <table>
        <tr>
            <% Html.Pager(Model, 1, p =>
           { %>
            <td  class="pagelinks">
                <%= Html.ActionLink<TopicsController>(c => c.IndexForAreas(p.Page), p.Page.ToString(), new { page = p.Page, @class = "Page@page" })%>
            </td>
            <% }); %>
        </tr>
    </table>
</div>

Master Page:

    <% Html.RenderAction("IndexForAreas", "Topics", new { area = "" }); %>
    <script type="text/javascript">
        $.post("<%= Html.BuildUrlFromExpressionForAreas<TopicsController>(c => c.IndexForAreas(null)) %>", { page: page },
                function (data) {
                    $(".topiccontainer").autoRender(data);
                },
                "json"
        );
    </script>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑看君怀她人 2024-09-09 05:58:13

下次您对 PURE 有任何疑问或问题时,可以将其发布到:http ://groups.google.com/group/Pure-Unobtrusive-Rendering-Engine

一般来说,您会在那里得到快速响应。

Next time you have a question or a problem about PURE you can post it at: http://groups.google.com/group/Pure-Unobtrusive-Rendering-Engine

In general, you'll get a fast response there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文