Sencha Touch 2.0和navigation.View - MVC [英] Sencha Touch 2.0 and navigation.View - MVC

查看:118
本文介绍了Sencha Touch 2.0和navigation.View - MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用一个按钮切换视图,在sencha文档的MVC上下文中绝对没有任何示例,尽管他们建议开发人员在MVC架构中使用它们的构建。我猜是因为Touch 2.0是相当新的。

I would like to switch views with a button, there is absolutely no examples of it in a MVC context in the sencha documentation although they recommend developers to use their build in MVC architecture. I guess its because Touch 2.0 is rather new.

http://docs.sencha.com/touch/2-0/#!/api

视频关于列表组件也是关于navigation.View,但是由于使用了列表组件,他们不会显示如何用按钮切换视图。

The video about the list component is also about navigation.View, but since the list component is used, they dont show how to switch views with a button.

视频:列表组件简介

这是我到目前为止的代码:

This is the code i have so far:

uddannelser.js(第一个视图)

uddannelser.js (First view)

Ext.define("VUCFyn.view.uddannelser", {
extend: "Ext.navigation.View",
xtype: "uddannelser",
requires: [
    "VUCFyn.view.avu"
],

config: {
    title: "Uddannelser",
    cls: "uddannelser",
    items: [
        {
            title: "Uddannelser",
            xtype: "container",
            margin: 20,
            layout: "vbox",
            items: [
                {
                    xtype: "button",
                    text: "AVU",
                    width: 100
                }
            ]
        }
    ]
}});

avu.js(uddannelser的子视图)

avu.js (subview of uddannelser)

Ext.define("VUCFyn.view.avu", {
extend: "Ext.Panel",
xtype: "avu",

config: {
    title: "AVU",
    cls: "avu",
    scrollable: true,
    items: [
        {
            xtype: "label",
            html: [
                "<p>Almen Voksenuddannelse - avu - er et tilbud om uddannelse til alle over 18 år. Du kan tage avu-fagene et ad gangen eller i en kombination med flere fag. Du kan også kombinere avu-fagene med andre enkeltfag på FVU og/eller hf.</p>",
                "<h5>AVU omfatter kernefagene:</h5>",
            ].join("")
        }
    ]
}});

Main.js(控制器)

Main.js (controller)

Ext.define('VUCFyn.controller.Main', {
extend: 'Ext.app.Controller',

config: {
    refs: {
        uddannelser: "uddannelser"
    },
    control: {
        "uddannelser": {
            tap: "showDetail"
        }
    }
},

showDetail: function () {
    this.getUddannelser().push({
        xtype: "avu"
    });
},

init: function () {

}});

如果有人可以告诉我如何做,基于上面的代码(或类似的)这将是伟大的。

Please, if someone could show me how to do it, based on the above code (or similar) that would be great.

btw:此主题中的答案: Sencha Touch 2 MVC - 如何用按钮切换视图对我来说不起作用。 (没有错误)我认为它为Sencha Touch 1.1,并且许多事情在2.0中显然已经改变了。

btw: the answers in this thread: Sencha Touch 2 MVC - how to switch views with button is not working for me. (No errors though) I think its for Sencha Touch 1.1, and a lot of things have apparently changed in 2.0

推荐答案

你是尝试收听 navigationview 上的点击事件,您已经给了uddannelser cls ?您的设置有几个问题:

Are you trying to listen for tap events on the navigationview you've given the uddannelser cls? There's a couple of issues with your setup;

首先,它看起来不像您在控制器中正确使用组件查询,请查看以下文档: http://docs.sencha.com/touch/2.4/apidocs/#! /api/Ext.ComponentQuery

Firstly, it doesn't look like you are using component queries properly in your controller, check this documentation: http://docs.sencha.com/touch/2.4/apidocs/#!/api/Ext.ComponentQuery

根据您希望控制器管理的视图中的这些组件数量,您可以给它一个id和通过#id搜索组件,或者您可以使用 xtype 和配置选项,例如navigationview [cls = uddannelser]

Depending on how many of these components in the view you want the controller to manage, you can either give it an id and search for the component by "#id" or you can use the xtype and a config option, such as "navigationview[cls=uddannelser]".

其次,您不能在 navigationview ,如果您想收听此组件上的点击事件,您必须在元素上收听点击事件,并传递事件。我怀疑你实际上正在试图听按钮上的tap事件,在这种情况下,您的控制器中会创建两个引用,一个用于 navigationview ,另一个用于按钮,在按钮上收听点击事件,然后按 navigationview 的面板就像现在一样。

Secondly, you can't listen for tap events on a navigationview, if you wanted to listen for tap events on this component you'd have to listen for the tap event on the element and relay the event. I suspect you are actually trying to listen for the tap event on the button though, in that case create two refs in your controller, one for the navigationview and one for the button, listen for the tap event on the button and push the panel on the navigationview like you are now.

这篇关于Sencha Touch 2.0和navigation.View - MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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