本文介绍了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.Panel 到另一个.

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.

如果有帮助,我将我的应用程序结构基于 Sencha 的 Pearce 先生的一个不错的 MVC 教程:

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 options 对象中添加的参数将传递给控制器​​上的 action 方法.

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——推荐的通过控制器传递数据的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 23:05
查看更多