VisualForce、Apex:Repeat,用于 Javascript 数组更新

发布于 2024-10-20 02:55:19 字数 907 浏览 1 评论 0原文

这是我在 Salesforce 开发板上提出的一个问题的扩展,该问题没有得到太多关注:

我有一个 VisualForce 页面,需要频繁更改以从控制器加载新信息并将该信息嵌入到 Javascript 数组中以供进一步使用。

当前解决方案:我已经成功使用 VisualForce“浏览器技术”,如下所述(在 Wiki 中): http://wiki.developerforce.com/index.php/Using_Browser_Technologies_in_Visualforce_-_Part_1

我用推荐的标签包围了 Javascript array.push:

<apex:repeat value="{!Object}" var="objects">       
    d.push( {
               element1: "{!objects.id}"            
    })
</apex:repeat>

问题:当整个页面刷新填充时,该数组被正确填充,并且当我使用“下拉菜单”修改对象上的过滤器(在控制器中)时,DOM 会更新(我可以看到页面上放置了新信息),

但是最终 Javascript 数组不会更改它的值除非我在整个页面上调用刷新,这会破坏部分刷新并对用户的系统造成某种冲击。

这个“必要的帖子”问题以前不是问题,即使我在 DOM 更新后直接调用包含此数组填充的 Javascript 函数,Javascript 数组也不会改变(所以我假设它已加载一次基于页面最初回发并且无法更改时 DOM 上的内容

this is an extension of a question I asked on the Salesforce developer boards that didn't get much play:

I have a VisualForce page that requires frequent changes to load new information from the controller and embed that information into a Javascript array for further use.

Curent solution: rI've had success using VisualForce 'Browser Technologies' as described here (in the Wiki): http://wiki.developerforce.com/index.php/Using_Browser_Technologies_in_Visualforce_-_Part_1

I surround the Javascript array.push with the recommended tags:

<apex:repeat value="{!Object}" var="objects">       
    d.push( {
               element1: "{!objects.id}"            
    })
</apex:repeat>

Issue: The array is correctly populated when an entire page refresh populates, and when I use my 'dropdown' to modify the filter on the object (in the controller), the DOM Is updated (I Can see new information being placed on the page),

Ultimately, however, the Javascript array doesn't change it's values unless I call a refresh on the entire page, which sort of defeats the Partial Refresh and is kind of shock to the system for users.

This 'necessary post' issue wasn't a problem before, and even when I directly call the Javascript function that contains this array population after the DOM has been updated the Javascript array doesn't change (So I'm assuming that it's loaded once based on what's at the DOM when the page initially posts back and can't be changed.

Thoughts?

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

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

发布评论

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

评论(1

々眼睛长脚气 2024-10-27 02:55:19

如果您想控制数组何时刷新,请将其包装在输出面板中,并将其 id 放入导致数据需要更新的任何内容的重新渲染属性中。当每个 dom 重新更新时,我之前必须使用它来重新附加一些自定义 jQuery 输入侦听器。

<apex:commandButton action="{!something}" rerender="scriptPanel"/>
<apex:outputPanel id="scriptPanel>
  <script>
     d = new Array();
     <apex:repeat value="{!objects}" var="object">
       d.push({
           element1: "{!objects.id}"            
       });
     </apex:repeat>
  </script>
</apex:outputPanel>

If you want to control when your array gets refreshed wrap it in an outputpanel and put its id in the rerender attribute of whatever causes the data to need an update. I had to use this previously to reattach some custom jQuery input listeners when every the dom was re-updated.

<apex:commandButton action="{!something}" rerender="scriptPanel"/>
<apex:outputPanel id="scriptPanel>
  <script>
     d = new Array();
     <apex:repeat value="{!objects}" var="object">
       d.push({
           element1: "{!objects.id}"            
       });
     </apex:repeat>
  </script>
</apex:outputPanel>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文