使用类作为中间体将属性更改从一个视图反映到另一个视图 [英] Reflect property change from one View into another View using a Class as intermediate

查看:17
本文介绍了使用类作为中间体将属性更改从一个视图反映到另一个视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确实提交了一个thread 这是(再次阅读后)完全错误的表述.这实际上是我想知道的:

I did submit a thread which was (after reading it again) totally wrong formulated. This is actually what i wanted to know:

在使用 MATE 的 Flex 应用程序中,假设我们有一个名为 View.mxml 的视图,具有名为 ViewProp 的属性和名为 ClassManager 的类,具有属性 ClassProp.假设我们有另一个名为 SecondView.mxml 的视图,其属性为 SecondProp.

In a Flex application using MATE suppose we have a view called View.mxml with a property called ViewProp and a class called ClassManager with a property ClassProp. Suppose we have another view called SecondView.mxml with a property SecondProp.

是否可以以某种方式定义以下内容:每当 ViewProp 更改时(在 View.mxml 中),ClassProp 也会在 ClassManager 中更改,这反过来反映了它在属性 SecondProp 中的 Secondview.mxml 中的更改?!

Is it possible to define somehow the following: whenever the ViewProp changes (in View.mxml) the ClassProp is also changed in ClassManager, which in turn reflects its changes in Secondview.mxml in property SecondProp?!

希望这次能准确描述!

提前致谢

推荐答案

这和你的第一个问题有点不同.

This is a bit different from your first question.

视图类不能直接访问模型类,因此视图类必须调度一个事件来改变模型类.

View classes MUST not access the model classes directly, and because of that the View class must dispatch an event to change the model class.

1.)您必须定义某种新事件

1.)You must define some kind of new event

public class ViewPropIsChangedEvent extends Event
{

  public static const SET_NEW_VALUE:String = "theNewValue";
  private var _value:Object;

  public ViewPropIsChangedEvent(type:String, value:Object, bubbling:Boolean=true, cancelable:Boolean=false)
  {
    super(type,bubbling,cancelable);
    _value = value;
  }
   public function get value():Object
  {
    return _value;
  }
}

2.) 当您在 View.mxml 中更改 ViewProp 时,您必须调度一个事件

2.) When you changed the ViewProp in View.mxml, you must dispatch an event

dispatchEvent(new ViewPropIsChangedEvent(ViewPropIsChangedEvent.SET_NEW_VALUE, theNewValue))

3.) 在 EventMap 中,您必须处理事件

3.) In the EventMap you must handle the event

</EventHandlers type="{ViewPropIsChangedEvent.SET_NEW_VALUE}"> 
  <PropertySetter generator="{ClassManager}" 
                  targetKey="ClassProp" 
                  source="{event.value}"/>
</EventHandlers>

4.) 在 ModelMap 中,您必须已经将 Secondview.SecondProp 绑定到 ClassManager.ClassProp

4.) In the ModelMap you must already bind the Secondview.SecondProp to ClassManager.ClassProp

<Injectors target="{Secondview}">
   <PropertyInjector targetKey="SecondProp" 
                     source="{ClassManager}"
                     sourceKey="ClassProp"/>
</Injectors>

这篇关于使用类作为中间体将属性更改从一个视图反映到另一个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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