Sencha Touch:MVC 应用程序中的动态图表标签

发布于 2024-12-06 14:47:57 字数 1233 浏览 0 评论 0原文

所以我有一个应用程序,我用它来了解有关触摸的更多信息。我根据在网上找到的教程获得了基本的框架设置,我可以在应用程序中点击一些东西。我集成了一个 sencha 触摸线图,效果很好。

问题是我想根据从服务器返回的数据填充图表的系列标签,而不是对标签进行硬编码。我的计划是一旦执行:

Ext.redirect('Chart/Index');

我会点击该控制器并加载商店。在商店的 onLoad 侦听器中,返回数据后,填充系列中的标题数组并渲染图表。我尝试将客户侦听器附加到图表视图,然后从商店侦听器执行它。

listeners: {
    load:function(el,records, success){
        App.fireEvent('myListener', records);
    }
 },

这对我不起作用,监听器未定义(我确实在图表视图中定义了它)。所以这不是我的解决方案。

然后我尝试给图表一个 id,并执行 Ext.query(#myChartName);返回一个 html 元素,而不是包装在 Ext 中可以执行的东西。

现在它是 extsj4,我可以在控制器中放置一个存储的侦听器,并在控制器中定义要执行的方法。它可以轻松访问控制器内的任何组件,这就是我解决此问题的方法。但这似乎不是 MVC 在触摸应用程序中的工作方式。我所看到的例子实际上是完全不同的。 (顺便说一句,这是为什么?)

在加载后获取商店中的数据并填充图表中的标签/图例时,我的最佳解决方案是什么?

更新 添加了相关代码的链接。我正在尝试将字符串(标签名称)添加到系列中的标题数组中。注意图表视图和商店。

图表视图

http://jsfiddle.net/5JhCu/2/

控制器

http://jsfiddle.net/3C4Tq/1/

商店

http://jsfiddle.net/LT6eh/

仅供参考,我尝试将侦听器添加到多个事物/对象,例如应用程序,视图,在控制器内,仍然没有运气。

So I have an app I am using to learn more about touch. I got the basic framework setup based on tutorials I have found around the net where I can bounce around the app clicking on things. I integrated a sencha touch line chart which works fine.

The problem is I want to populate the series labels for the chart based on data that comes back from the server, not hard code the labels. My plan was to once execute:

Ext.redirect('Chart/Index');

I would hit that controller and load the store. In the onLoad listener for the store, once the data is returned, populate the title array in the series and render the chart. I tried to attach a customer listener to the chart view, and then execute it from the store listener.

listeners: {
    load:function(el,records, success){
        App.fireEvent('myListener', records);
    }
 },

That isn't working for me, listener is undefined (I do have it defined in the chart view). So that isn't my solution.

Then I tried to give the chart an id, and do a Ext.query(#myChartName); That returned a html element, not something wrapped in Ext that can be executed.

Now it extsj4, I can put a listener for a store in the controller, and define a method in the controller to execute. It can easily access any component within the controller and would be how I would solve this issue. But that doesn't seem to be how MVC works in the touch apps. The examples I have seen are laid out drastically different in fact. (Why is that btw?)

What's my best solution in taking the data in my store after load and populating the labels/legend in my chart?

UPDATE
Added links to the code in question. I am trying to add strings (the label names) to the title array in the series. Notice the Chart View & the Store.

Chart view

http://jsfiddle.net/5JhCu/2/

Controller

http://jsfiddle.net/3C4Tq/1/

Store

http://jsfiddle.net/LT6eh/

FYI, I tried adding the listener to multiple things/objects like the app, the view, within the controller, still no luck.

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

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

发布评论

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

评论(1

噩梦成真你也成魔 2024-12-13 14:47:58

您是否尝试过 Ext.getCmp('myChartId') 来访问图表组件?

Did you try Ext.getCmp('myChartId') to get access to the chart component?

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