簡體   English   中英

當'items'為null時,AngularDart篩選器調用方法將引發錯誤

[英]AngularDart Filter call method throws error when 'items' is null

當我使用“過濾器”加載組件時,將在設置“項目”參數之前運行“調用”方法。 因此,我從第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列表是由屬性設置的,或者如果未提供,則在attach方法中設置。 在這種情況下,它是由屬性設置的。

@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;
            });
        }
    }
}

其他人有沒有經歷過? 這里有計時錯誤嗎?

謝謝山姆

經過更多的調試后,我確認我的列表在'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的了解不足,以至於不知道那是什么。

您可以使用一個空列表初始化該字段

List<AppSessionModel> appSessions = [];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM