我可以将 javascript 对象传递回 atk4 页面吗?
从 ATK4 页面,我可以使用像这样的 javascript 帮助程序文件来调用 jqplot,
在页面上
$chart = $p->add('jqplot', null, 'chart1');
$chart->setSeries(array(10,20,15));
定义像这样的 jqplot.php
class jqplot extends View {
function render()
{
$plot=$this->js(true)->univ()->jqplot($this->series, $this->opts);
parent::render();
return $this;
}
}
并在 js 帮助程序文件中,将 php 调用链接到 javascript
$.each({
jqplot: function(series, opts){
console.log('jqplot series',series);
console.log('jqplot options',opts);
$plot=$.jqplot(this.jquery.attr("id"), series, opts);
return $plot;
}
}
如果我在页面上有一个图表并且使用 ajaxec 调用重新加载它,它工作正常,但如果我有多个图表彼此相邻,则只有第一个图表可以,如果我调用重新加载,旁边的图表会完全消失。
我真正想做的是在图表上调用 jqplot replot 函数并从页面传递新数据,但我该怎么做? jshelper 中的 $plot 对象包含一个 javascript 对象,我需要这个对象来调用 replot 。
我在想也许我可以在第一次创建对象时将对象存储在javascript关联数组中,然后当我调用replot时,查找id,如果找到,则在对象上调用replot,但不确定这段代码是什么样的,或者我是否有权利方法所以任何帮助表示赞赏。
预先感谢您的帮助。
From an ATK4 page, i can call jqplot using a javascript helper file like this
on the page
$chart = $p->add('jqplot', null, 'chart1');
$chart->setSeries(array(10,20,15));
define a jqplot.php like this
class jqplot extends View {
function render()
{
$plot=$this->js(true)->univ()->jqplot($this->series, $this->opts);
parent::render();
return $this;
}
}
and in a js helper file, link the php call to the javascript
$.each({
jqplot: function(series, opts){
console.log('jqplot series',series);
console.log('jqplot options',opts);
$plot=$.jqplot(this.jquery.attr("id"), series, opts);
return $plot;
}
}
If i have one chart on a page and reload it with an ajaxec call, it works fine but if i have several charts next to each other, only the first one is ok and the one next to it completely disappears if i call reload.
What i really want to do is call the jqplot replot function on the chart and pass it new data from the page but how can i do this ? The $plot object in the jshelper holds a javascript object and i need this object to call replot on it.
I am thinking maybe i can store the object when first created in a javascript associative array and then when i call replot, lookup the id and if found, call replot on the object but not sure what this code looks like or whether i have the right approach so any help appreciated.
Thanks in advance for you assistance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
想要实现这个目标恐怕是相当困难的。首先,您需要正确处理 jqPlot 的破坏。您需要一个合适的 jQuery UI 小部件,能够通过解构函数恢复所有内容。然后你就可以让它工作了。
就 Agile Toolkit 而言,它使用 JavaScript 销毁包含 jqPlot 的元素,重新加载 HTML 并重新执行 JavaScript。
It probably would be quite difficult to achieve this. First you need to properly handle destruction of jqPlot. You'll need a proper jQuery UI widget capable of restoring everything through a de-constructor. Then you might get it to work.
As far as Agile Toolkit is concern, it destroys the element containing your jqPlot using JavaScript, re-loads HTML and re-executes JavaScript.