我可以将元素添加到 RepeatingView 而不刷新后者吗? [英] Can I add an element to a RepeatingView without refreshing the latter?

查看:26
本文介绍了我可以将元素添加到 RepeatingView 而不刷新后者吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个包含复杂元素(例如包含小程序)的 RepeatingView.我想使用ajax向RepeatingView添加(或删除)一个新元素,但我不想刷新所有元素,因为这会导致applet重新加载,这显然是我不想要的.

Let's say that I have a RepeatingView with complex elements (for example containing applets). I want to add (or delete) a new element to RepeatingView with ajax, but I don't want to refresh all the elements, because it would cause applets to reload, which I obviously don't want.

我使用的是 wicket 1.4.18

I am using wicket 1.4.18

只添加到我想添加的元素,不起作用,我得到:尝试执行标记更新时未找到带有 id (...) 的组件.确保在要更新其标记的组件上调用了 component.setOutputMarkupId(true)

Adding to target only the element that I want to add, does not work, I get: Component with id (...) was not found while trying to perform markup update. Make sure you called component.setOutputMarkupId(true) on the component whose markup you are trying to update

推荐答案

看看这篇 Wicket in Action 文章中建议的方法:通过ajax只重绘新创建的repeater项

Take a look at the approach suggested in this Wicket in Action article: Repainting only newly-created repeater items via ajax

当你想通过 AJAX 添加一个新元素时的问题是没有根标记标签来为 Wicket 重新绘制新添加的项目.

The problem when you want to add a new element via AJAX is that there's no root markup tag for the newly added item for Wicket to repaint it.

引用文章:

诀窍是给 Wicket 一个标签以通过 Ajax 重新绘制,它可以是通过执行以下操作来完成:

The trick is to give Wicket a tag to repaint via Ajax which can be accomplished by doing the following:

  1. 创建标记标签来表示新项目
  2. 将其添加到标记中的正确位置
  3. 让 Wicket 通过 Ajax 重新绘制它

文章中的代码基本上在 ajax 提交按钮的回调中预先添加了一些 javascript,它实际上创建了具有适当 id 的标记,以便 Wicket 能够在稍后将其添加到 AjaxRequestTarget 时替换该元素代码>.

The code in the article basically prepends some javascript in the ajax submit button's callback that actually creates the markup with the appropriate id for Wicket to be able to replace the element later, when you add it to the AjaxRequestTarget.

这篇关于我可以将元素添加到 RepeatingView 而不刷新后者吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆