反映财产的变化从一个视图到使用类作为中间另一个View视图、财产、View

2023-09-08 14:20:48 作者:╭ァ再回首ヾ恍然如夢

我没有提交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,从而体现其在Secondview.mxml物业SecondProp的变化改变了吗?!

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?!

我希望这次能正确描述它!

I hope this time to have described it correctly!

在此先感谢

推荐答案

这是你的第一个问题有点不同。

This is a bit different from your first question.

查看类,因为那View类必须分派事件改变模型类不能直接访问模型类,和。

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>