문제

I have a problem with my application in flex4, i have this code for my button:

<buttons:MyButton id="btnNewPost"
    label="{I18nManager.getInstance().main.newPost}"
    minWidth="170"
    click="{doSomething()}"
    creationComplete="btnNewPost_creationCompleteHandler(event)"/>

And on creation complete i have this code:

if (this.newItemButtonEnabledWithCategories)
{
    BindingUtils.bindProperty(this.btnNewPost, "enabled", ModelLocator.getInstance(), "currentCategory");
}

Well, so this is clear, when property currentCategory is not null, then the button will be enabled.

What i want:

I want to dind the property enable to another property of the ModelLocator, itemMode but only if itemMod is ready

I tried BindingUtils.bindProperty(this.btnNewPost, "enabled", ModelLocator.getInstance(), "itemMode"); without luck because if itemMode has any value then the property enabled is always true

Is there any way to only enable item if itemMode is ready?

도움이 되었습니까?

해결책

You might want to use bindSetter rather than bindProperty. This allows you to have a method handle when the property has changed:

BindingUtils.bindSetter(itemModeChanged, 
                        ModelLocateor.getInstance(), 
                        "itemMode");

protected function itemModeChanged(mode:String):void
{
    this.btnNewPost.enabled = (mode == "ready");
}

(As another thought, is there any reason you can't specify the binding in the MXML? enabled="{ModelLocator.getInstance().itemMode == 'ready'} I haven't tried this exact example to verify it works, but I think it should.)

다른 팁

You could bind to a new property, itemModeIsReady in your ModelLocator. In your setter for itemMode, dispatch a PropertyChangeEvent for itemModeIsReady and have an appropriate getter:

public function set itemMode(mode:String):void {
  var previousValue = _itemMode;
  //existing 
  dispatchEvent(PropertyChangeEvent.createUpdateEvent(this, "itemModeIsReady", previousValue == "ready", mode == "ready"));
}

[Bindable]
public function get itemModeIsReady():Boolean {
  return itemMode == "ready";
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top