Sencha Touch MVC - 推荐通过控制器传递数据的方法? [英] Sencha Touch MVC -- recommended ways of passing data through the controller?

查看:105
本文介绍了Sencha Touch MVC - 推荐通过控制器传递数据的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Sencha Touch作为移动应用,并且正在使用MVC功能。我喜欢Sencha,但是当使用控制器将数据从一个屏幕传递到下一个时,我有点麻烦。

I'm using Sencha Touch for a mobile app and am using the MVC functionality in it. I like Sencha quite a bit but I'm having a little trouble when it comes to passing data from one 'screen' to the next using the controller.

有一个记录属性与许多Sencha小部件相关联 - 例如在Ext.list中指示当前选定的记录 - 并且由于某种原因,我无法完全了解如何从Ext传递类似的内容。面板另一个。

There's a "record" property associated with a number of the Sencha widgets --indicating the currently selected record in an Ext.list for instance-- and for some reason I can't quite get there as to how to pass something like that from an Ext.Panel to another one.

例如,我有一个Ext.Panel,其中包含一个Ext.Store的数据,包括一个地址。我有另一个Ext.Panel将显示地图。我需要将这个地址传递给地图的面板,但不知道如何。这是我从第一个面板中尝试的:

For instance, I have an Ext.Panel with data in it from an Ext.Store, including an address. I have another Ext.Panel that will show a map. I need to pass this address to the map's panel, but am not sure how. Here's what I'm trying from the first panel:

                listeners: {
                'tap': function () {
                    Ext.dispatch({
                        controller: app.controllers.establishments,
                        action: 'showMap',
                        id: record.getId(),
                        data: record.data
                    });
                }

我可以看到有一点,试图使用两个控制器中的'id'和'data'配置选项,试图通过任何必要的方式获取数据到地图面板。

I'm floundering a bit as you can see, trying to use both an 'id' and 'data' config option in the controller in an attempt to get data to the map panel, by any means necessary.

我不一定需要这个具体问题的答案,但是如果您有关于如何做到这一点的建议 - 基本上是传递数据的最佳做法一个屏幕到下一个。

I don't necessarily need a answer for this specific problem, but if you had suggestions on how to do this in general-- basically, best practices for passing data from one screen to the next.

如果有帮助,我将基于我的应用程序的结构放在一个漂亮的MVC教程由皮尔斯先​​生在Sencha:

If it helps, I'm basing my app's structure on a nice MVC tutorial by Mr. Pearce at Sencha:

http://www.sencha.com/learn/Tutorial:A_Sencha_Touch_MVC_application_with_PhoneGap

非常感谢!

推荐答案

我觉得你在右边跟Ext.Dispatch。您在Dispatch选项对象中添加的参数将传递给控制器​​上的操作方法。

I think you're on the right track with Ext.Dispatch. The parameters you add in the Dispatch options object are passed to the action method on the controller.

例如

showMap: function(options){ 
               var id = options.id; 
               //load data based on the id and pass it to your map
               ...
         }

我也认为你应该在Dispatch选项对象上设置historyUrl,以便如果刷新页面,ID仍然会被发送到控制器操作。

I also think you should set the historyUrl on the Dispatch options object so that if they refresh the page the id will still get sent to the controller action.

这篇关于Sencha Touch MVC - 推荐通过控制器传递数据的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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