Nativescript UI RadListView的问题

时间:2016-09-13 15:22:02

标签: listview nativescript radlistview nativescript-telerik-ui

我无法从使用常规ListView的数据初始化RadListView。我有一个可观察的数组,应该在列表视图中输出项目,当使用常规的旧ListView时,它工作正常。我想利用RadListView中开箱即用的滑动功能,但是我只是尝试使用常规ListView中使用的相同数据进行初始化时得到了一个冗长的错误。

// THIS DOES NOT WORK.                
<lv:RadListView items="{{ addedParents }}" >

    <lv:RadListView.listViewLayout>
        <lv:ListViewLinearLayout scrollDirection="Vertical"/>
    </lv:RadListView.listViewLayout>
    <lv:RadListView.itemTemplate>
        <StackLayout orientation="vertical">
            <Label fontSize="20" text="{{ first_name }}"/>

            <Label fontSize="14" text="{{ email }}"/>

        </StackLayout>
    </lv:RadListView.itemTemplate>
</lv:RadListView>   




// THIS WORKS.
<ListView items="{{ addedParents }}" id="added_parents">
    <ListView.itemTemplate>
        <GridLayout columns="*, auto" rows="*, 1">
            <Label text="{{ first_name + ' ' + last_name + ' (' + email + ')'}}"/>
        </GridLayout>
    </ListView.itemTemplate>
</ListView>

我得到的错误是:

CONSOLE WARN file:///app/tns_modules/nativescript-telerik-ui/listview/listview.js:358:14: The TypeScript constructor "TKListViewDataSourceImpl" will not be executed.
CONSOLE WARN file:///app/tns_modules/nativescript-telerik-ui/listview/listview.js:499:14: The TypeScript constructor "ExtendedListViewCell" will not be executed.
*** Assertion failure in -[TKCollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.60.7/UICollectionView.m:4625
*** JavaScript call stack:
        (
            0   insertItemsAtIndexPaths@[native code]
            1   onSourceCollectionChanged@file:///app/tns_modules/nativescript-telerik-ui/listview/listview.js:881:45
            2   onSourceCollectionChangedInternal@file:///app/tns_modules/nativescript-telerik-ui/listview/listview-common.js:619:43
            3   handler@file:///app/tns_modules/ui/core/weak-event-listener.js:30:38
            4   notify@file:///app/tns_modules/data/observable/observable.js:155:31
            5   push@file:///app/tns_modules/data/observable-array/observable-array.js:99:20
            6   onShownModally@file:///app/views/modals/manageparents/manageparents.js:42:30
            7   notify@file:///app/tns_modules/data/observable/observable.js:155:31
            8   _raiseShowingModallyEvent@file:///app/tns_modules/ui/page/page-common.js:259:20
            9   _showNativeModalView@file:///app/tns_modules/ui/page/page.js:302:56
            10  showModal@file:///app/tns_modules/ui/page/page-common.js:202:38
            11  manageParents@file:///app/views/parent/kid/kid.js:156:19
            12  notify@file:///app/tns_modules/data/observable/observable.js:155:31
            13  _emit@file:///app/tns_modules/data/observable/observable.js:174:24
            14  tap@file:///app/tns_modules/ui/button/button.js:19:24
            15  UIApplicationMain@[native code]
            16  start@file:///app/tns_modules/application/application.js:233:26
            17  anonymous@file:///app/app.js:3:24
            18  evaluate@[native code]
            19  moduleEvaluation@:1:11
            20  @:8:48
            21  promiseReactionJob@:1:11
        )
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of items in section 0.  The number of items contained in an existing section after the update (1) must be equal to the number of items contained in that section before the update (1), plus or minus the number of items inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).'
        *** First throw call stack:
        (
            0   CoreFoundation                      0x03d16494 __exceptionPreprocess + 180
            1   libobjc.A.dylib                     0x037d0e02 objc_exception_throw + 50
            2   CoreFoundation                      0x03d1632a +[NSException raise:format:arguments:] + 138
            3   Foundation                          0x01296322 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 118
            4   UIKit                               0x01fe2a6e -[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:] + 17081
            5   UIKit                               0x01fde7b0 -[UICollectionView _endItemAnimationsWithInvalidationContext:] + 48
            6   UIKit                               0x01fde54c -[UICollectionView _updateRowsAtIndexPaths:updateAction:] + 400
            7   UIKit                               0x01fde5af -[UICollectionView insertItemsAtIndexPaths:] + 48
            8   TelerikUI                           0x036db9fb -[TKCollectionView insertItemsAtIndexPaths:] + 171
            9   TelerikUI                           0x03543bc1 __38-[TKListView insertItemsAtIndexPaths:]_block_invoke + 97
            10  UIKit                               0x017050c9 +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 608
            11  UIKit                               0x01705679 +[UIView(UIViewAnimationWithBlocks) animateWithDuration:animations:] + 115
            12  TelerikUI                           0x03543aa2 -[TKListView insertItemsAtIndexPaths:] + 386
            13  NativeScript                        0x00c43ee8 ffi_call_i386 + 24
        )
com.apple.CoreSimulator.SimDevice.57D7D435-74D2-4D36-8ECE-D1ABA70AE4CF.launchd_sim[662] (UIKitApplication:com.cubbynotes.pocketnanny[0xdcbf][3806]): Service exited due to signal: Abort trap: 6

更新: 所以,我正在初始化showsMo​​dally处理程序中的数据。将我更新数组的代码移动到加载的处理程序不会导致我的应用程序崩溃,但列表视图不会显示。这是我的初始化代码:

var addedParents = new ObservableArray();
var parentsArray = [];

var pageData = new Observable({
    addedParents: addedParents,
    kid_id: false,
    loading: false
});

var context;
var closeCallback;
function onShownModally(args) {
    page = args.object;
    parentsArray = args.context.parents;
    pageData.set('kid_id', args.context.id);
    closeCallback = args.closeCallback;
}
exports.onShownModally = onShownModally;

exports.loaded = function(args) {
    page = args.object;
    while (addedParents.length) addedParents.pop();
    if (parentsArray && parentsArray.length) {
        for (var i = 0; parentsArray.length > i; i++) {
            addedParents.push(parentsArray[i]);
        }
    }
    page.bindingContext = pageData;
}

以下是症状: screenshot

这是由xml生成的:

<Label text="I am a radlistview" />
<lv:RadListView items="{{ addedParents }}" id="added_parents">

    <lv:RadListView.listViewLayout>
        <lv:ListViewLinearLayout scrollDirection="Vertical"/>
    </lv:RadListView.listViewLayout>
    <lv:RadListView.itemTemplate>
        <StackLayout orientation="vertical">
            <Label fontSize="20" text="{{ first_name }}"/>

            <Label fontSize="14" text="{{ email }}"/>

        </StackLayout>
    </lv:RadListView.itemTemplate>
</lv:RadListView> 

<Label text="I am a regular old list view." />                

<ListView items="{{ addedParents }}" id="added_parents" separatorColor="#ffffff">
    <ListView.itemTemplate>
        <GridLayout columns="*, auto" rows="*, 1">
            <Label text="{{ first_name + ' ' + last_name + ' (' + email + ')'}}"/>
        </GridLayout>
    </ListView.itemTemplate>
</ListView>

0 个答案:

没有答案