【问题标题】:AngularDart Filter call method throws error when 'items' is null当'items'为空时,AngularDart过滤器调用方法抛出错误
【发布时间】:2016-01-14 21:56:37
【问题描述】:

当我使用“过滤器”加载组件时,“调用”方法在设置“项目”参数之前运行。所以我从第 200 行收到重复错误。最终,“items”被发送,“call”方法运行没有错误。

The null object does not have a method 'where'.

NoSuchMethodError: method not found: 'where'
Receiver: null
Arguments: [Closure: (dynamic) => dynamic]

STACKTRACE:
#0      Object._noSuchMethod (dart:core-patch/object_patch.dart:42)
#1      Object.noSuchMethod (dart:core-patch/object_patch.dart:45)
#2      Filter.call (package:angular/formatter/filter.dart:200:26) 

这是我第一次使用 AngularDart 实现过滤器,这发生在我尝试过的两个组件中。我的模板没有什么特别之处:

<tr ng-repeat="appSession in appSessions | orderBy: orderByList | filter: filterObject">

appSessions 列表由属性设置,如果未提供,则在附加方法中设置。在这种情况下,它是由属性设置的。

@NgOneWay("app-sessions") List<AppSessionModel> appSessions;
@NgOneWay("mobile-user-id") int mobileUserID;

void attach() {

    if (appSessions == null) {
        if (mobileUserID != null) {
            appSessionManager.getForUser(mobileUserID).then((sessions) {
                appSessions = sessions;
            });
        } else if (!fromUserTable) {
            appSessionManager.getOpen().then((sessions) {
                appSessions = sessions;
            });
        }
    }
}

有其他人经历过吗?这里有时间错误吗?

谢谢, 山姆

【问题讨论】:

  • 您能添加更多代码吗?值是如何设置的?
  • @GünterZöchbauer 我添加了设置“appSessions”的代码。据我所知,没有什么不寻常的。我有另一个组件,其中列表包含地图,而不是对象,但我仍然收到此错误。

标签: dart angular-dart


【解决方案1】:

经过更多调试,我确认我的列表在 'attach' 方法中永远不会为空,并且我确认 Filter.call 在 'attach' 方法之后运行。原来是与模板中的“orderBy”有关的问题。

我有这个:

<tr ng-repeat="appSession in appSessions | orderBy: orderByList | filter: filterObject">

如果我切换 'orderBy' 和 'filter',则不再有 Filter.call 错误:

<tr ng-repeat="appSession in appSessions | filter: filterObject | orderBy: orderByList">

我调试了 OrderBy.call,但它没有将 'items' 返回为 null,所以问题似乎在 OrderBy 和 Filter 之间,但我对 AngularDart 的了解还不够,不知道那可能是什么。

【讨论】:

    【解决方案2】:

    你可以用一个空列表初始化字段

    List<AppSessionModel> appSessions = [];
    

    【讨论】:

    • 那行不通。该错误似乎是在映射属性之前引发的,但我还没有调试到那个详细程度。
    • 确保appSessions 未在attach() 中设置为null
    猜你喜欢
    • 2020-05-30
    • 2021-12-17
    • 2014-02-14
    • 2020-09-29
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 2018-02-13
    • 1970-01-01
    相关资源
    最近更新 更多