简体   繁体   English

VisualForce,Apex:重复,用于Javascript数组更新

[英]VisualForce, Apex:Repeat, for Javascript array Update

this is an extension of a question I asked on the Salesforce developer boards that didn't get much play: 这是我在Salesforce开发板上询问的一个问题的扩展:

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. 我有一个VisualForce页面,需要经常更改从控制器加载新信息并将该信息嵌入到Javascript数组中以供进一步使用。

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 Curent解决方案:我已经成功使用了VisualForce'浏览器技术',如此处所述(在Wiki中): http ://wiki.developerforce.com/index.php/Using_Browser_Technologies_in_Visualforce_-_Part_1

I surround the Javascript array.push with the recommended tags: 我用推荐的标签包围Javascript array.push:

<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), 问题:当整个页面刷新填充时,阵列被正确填充,当我使用“下拉”修改对象上的过滤器(在控制器中)时,DOM被更新(我可以看到新信息被放置在页面上) )

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. 然而,最终,Javascript数组不会改变它的值,除非我在整个页面上调用刷新,这会使部分刷新失败并且对用户来说是一种冲击。

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. 这个“必要的帖子”问题以前不是问题,甚至在我更新DOM后直接调用包含此数组的Javascript函数时,Javascript数组也不会改变(所以我假设它已经加载了一次基于当页面最初回发并且无法更改时DOM上的内容。

Thoughts? 思考?

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. 如果要控制数组何时刷新,请将其包装在outputpanel中,并将其id放在rerender属性中,以使数据需要更新。 I had to use this previously to reattach some custom jQuery input listeners when every the dom was re-updated. 在重新更新每个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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM