Visual Component 中的注入模型
我正在使用欧芹框架。我正在尝试在自定义视觉树组件中注入模型;
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经找到了如何解决这个问题。如果我们尝试在可视组件中注入某种东西,我们应该以与配置可视组件相同的方式配置它。
<代码>...
}
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.
...
}
Mb someone has some other solution?
不确定您是否想要欧芹来实例化您的 CustomTree。
相反,将模型注入到视图中,并让 mxml 中的 CustomTree 实例绑定到模型。
配置:
MXML:
您不需要注入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:
MXML:
You don't need id for injection, you could inject by type, just drop the ids from inject tag and config for model.