Visual Component 中的注入模型

发布于 2024-12-01 07:58:26 字数 1007 浏览 1 评论 0原文

我正在使用欧芹框架。我正在尝试在自定义视觉树组件中注入模型;

private var _model:Model

[Bindable]

public function get model():Model
{
  return _model;
}

public function set model(value:Model):void
{
  _model = value;
}

构建配置:

<Object id="customTree" type="{CustomTree}">
  <Property name="model" idRef="model"/>
</Object>

然后我在 mxml 中使用了这棵树:

<components:CustomTree
        id="categoriesTree"
        width="100%" height="100%"
        labelField="@title"
        right="0" bottom="0" left="0" top="10"           
        doubleClickEnabled="true"
        maxHorizontalScrollPosition="250"
        horizontalScrollPolicy="auto"
        dragEnabled="true"
        dropEnabled="true"
        dataProvider="{model.dataHolder}"
        />

我尝试覆盖父函数,但出现错误。 (模型为空); 覆盖受保护的函数dragDropHandler(event:DragEvent):void { 模型.action = "drop" 我在模型

设置器中设置了断点,它被执行了,但模型仍然为空;

问题出在哪里?

I'm using Parsley framework. I'm trying to inject model in custom visual Tree component;

private var _model:Model

[Bindable]

public function get model():Model
{
  return _model;
}

public function set model(value:Model):void
{
  _model = value;
}

Build Config:

<Object id="customTree" type="{CustomTree}">
  <Property name="model" idRef="model"/>
</Object>

Then I have use this tree in mxml:

<components:CustomTree
        id="categoriesTree"
        width="100%" height="100%"
        labelField="@title"
        right="0" bottom="0" left="0" top="10"           
        doubleClickEnabled="true"
        maxHorizontalScrollPosition="250"
        horizontalScrollPolicy="auto"
        dragEnabled="true"
        dropEnabled="true"
        dataProvider="{model.dataHolder}"
        />

I had try override parent function and I have got an error. (model is null);
override protected function dragDropHandler(event:DragEvent):void
{
model.action = "drop"
}

I had set breakpoint in model setter and it was executed but model still null;

Where is the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冷弦 2024-12-08 07:58:26

我已经找到了如何解决这个问题。如果我们尝试在可视组件中注入某种东西,我们应该以与配置可视组件相同的方式配置它。

public class CustomTree extends Tree
{

public function CustomTree ()
{
  super();
  this.addEventListener(Event.ADDED_TO_STAGE, configure);
}

protected function configure(event:Event):void
{
  this.dispatchEvent(new Event ('configureIOC', true));
}

<代码>...
}

MB有人有其他解决方案吗?

I have found how to fix this problem. If we try inject smth in visual component we should configure it at the same way as we configure visual components.

public class CustomTree extends Tree
{

public function CustomTree ()
{
  super();
  this.addEventListener(Event.ADDED_TO_STAGE, configure);
}

protected function configure(event:Event):void
{
  this.dispatchEvent(new Event ('configureIOC', true));
}

...
}

Mb someone has some other solution?

泅人 2024-12-08 07:58:26

不确定您是否想要欧芹来实例化您的 CustomTree。
相反,将模型注入到视图中,并让 mxml 中的 CustomTree 实例绑定到模型。

配置:

<Object id="model" type="Model"/>

MXML:

<mx:Script>
        <![CDATA[
[Inject(id='model')]
[Bindable]
public var model:Model;
]]>
    </mx:Script>

<components:CustomTree
        id="categoriesTree"
        width="100%" height="100%"
        labelField="@title"
        right="0" bottom="0" left="0" top="10"           
        doubleClickEnabled="true"
        maxHorizontalScrollPosition="250"
        horizontalScrollPolicy="auto"
        dragEnabled="true"
        dropEnabled="true"
        dataProvider="{model.dataHolder}"
        />

您不需要注入ID,您可以按类型注入,只需从注入标签和模型配置中删除ID即可。

Not sure that you want parsley to instantiate your CustomTree.
Instead inject model into the view and let CustomTree instance in mxml bind to model.

Config:

<Object id="model" type="Model"/>

MXML:

<mx:Script>
        <![CDATA[
[Inject(id='model')]
[Bindable]
public var model:Model;
]]>
    </mx:Script>

<components:CustomTree
        id="categoriesTree"
        width="100%" height="100%"
        labelField="@title"
        right="0" bottom="0" left="0" top="10"           
        doubleClickEnabled="true"
        maxHorizontalScrollPosition="250"
        horizontalScrollPolicy="auto"
        dragEnabled="true"
        dropEnabled="true"
        dataProvider="{model.dataHolder}"
        />

You don't need id for injection, you could inject by type, just drop the ids from inject tag and config for model.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文