绑定时遇到问题

发布于 2024-08-27 05:29:20 字数 920 浏览 13 评论 0原文

我不确定我是否误解了 Flex 中的绑定。我正在使用 Cairngorm 框架。我有以下组件,其代码如下:

        [Bindable]
        var _model:LalModelLocator = LalModelLocator.getInstance();
....
<s:DataGroup    dataProvider="{_model.friendsSearchResults}"
                     includeIn="find"
                     itemRenderer="com.lal.renderers.SingleFriendDisplayRenderer">
            <s:layout>
                <s:TileLayout orientation="columns"    requestedColumnCount="2" />
            </s:layout>         </s:DataGroup>

在模型定位器中:

[Bindable]
public var friendsSearchResults:ArrayCollection = new ArrayCollection();

在项目渲染器内部有一个调用命令的按钮,在命令结果内部有一行如下所示:

model.friendsSearchResults = friendsSearchResults;

放置断点并单步执行代码我确认了这一点like 被调用,friendsSearchResults 被更新。

据我了解,如果我更新可绑定变量,它应该自动重新渲染具有该变量的 dataProvider 的 s:DataGroup 。

I'm not sure if I'm misunderstanding the binding in Flex. I'm using Cairngorm framework. I have the following component with code like:

        [Bindable]
        var _model:LalModelLocator = LalModelLocator.getInstance();
....
<s:DataGroup    dataProvider="{_model.friendsSearchResults}"
                     includeIn="find"
                     itemRenderer="com.lal.renderers.SingleFriendDisplayRenderer">
            <s:layout>
                <s:TileLayout orientation="columns"    requestedColumnCount="2" />
            </s:layout>         </s:DataGroup>

in the model locator:

[Bindable]
public var friendsSearchResults:ArrayCollection = new ArrayCollection();

Inside the item renderer there is a button that calls a command and inside the command results there is a line like this:

model.friendsSearchResults = friendsSearchResults;

Putting break points and stepping through the code I confirmed that this like gets called and the friendsSearchResults gets updated.

To my understanding if I update a bindable variable it should automatically re-render the s:DataGroup which has a dataProvider of that variable.

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

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

发布评论

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

评论(1

指尖上得阳光 2024-09-03 05:29:20

代码示例中没有任何明显错误。它应该有效,所以我认为其他地方有问题。

我建议在分配 dataProvider 以及分配 model.friendsSearchResults 的位置设置一个断点。确保它们都指向同一个对象实例。然后逐步执行属性分配和相应的事件。

为了使调试更容易,您可以切换为使用命名事件而不是默认事件。对于命名事件,只有对您的特定属性感兴趣的事件侦听器才会被触发,而不是侦听任何属性更改的任何侦听器。这更容易调试并且运行速度更快。例如,将:更改

[Bindable]
public var results:ArrayCollection;

[Bindable("resultsChanged")]
private var _results:ArrayCollection;
public function get results():ArrayCollection {
    return _results;
}
public function set results(value:ArrayCollection):Void {
    _results = value;
    dispatchEvent(new Event("resultsChanged"));
}

另一件需要记住的事情是绑定隐藏了某些错误,例如空引用异常。他们假设该值根本不可用并抑制错误。单步执行分配和相关绑定将有助于找到这样的问题。

There's nothing obviously wrong in the code sample. It should work so I think there's a problem elsewhere.

I would recommend setting a breakpoint where the dataProvider is assigned and also where model.friendsSearchResults is assigned. Make sure they're both pointing to the same object instance. Then step through the property assignment and corresponding event.

To make debugging easier you can switch to using a named event instead of the default. With a named event, only event listeners interested in your particular property are triggered instead of any listeners listening for any property change. This is easier to debug and will run faster. For example, change:

[Bindable]
public var results:ArrayCollection;

to

[Bindable("resultsChanged")]
private var _results:ArrayCollection;
public function get results():ArrayCollection {
    return _results;
}
public function set results(value:ArrayCollection):Void {
    _results = value;
    dispatchEvent(new Event("resultsChanged"));
}

Another thing to keep in mind is that bindings hide certain errors like null reference exceptions. They assume the value simply isn't available yet and suppress the error. Stepping through the assignment and related bindings will help find a problem like this.

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