When deleting an item from StackedView, other items are unexpectedly deleted or hidden

11 views
Skip to first unread message

Amilie Napier

unread,
Apr 24, 2013, 6:51:25 PM4/24/13
to sproutc...@googlegroups.com
I'm displaying a list of items in a StackedView within a ScrollView. Each item has a delete button that the user can use to remove that item from the list. It behaves as expected if the user deletes either the first or the last item in the list. However, if they delete an item from the middle of the list, all items below the deleted item are also removed from the view. The items above the deleted item remain in the DOM, but they are hidden from view because the height of the StackedView gets set to zero.

I've tried using a ListView instead of StackedView, but the only difference is that the height is not reset to zero after an item is deleted. The items after the deleted item are still removed from the view.

Any help on this would be appreciated.

Here's the relevant chunk of code from my view:

collection: SC.ScrollView.design({
    contentView: SC.StackedView.design({
        contentBinding: 'MyListContentController.arrangedObjects',
        exampleView: SC.View.design(SC.StaticLayout, {
            useStaticLayout: YES,
            childViews: 'data deleteButton'.w(),
            data: SC.TextFieldView.design({
                //........
            }),
            deleteButton: SC.ButtonView.extend({
                //........
                action: 'removeEntry'
            }),
            removeEntry: function () {
                MyListContentController.removeObject(this.get('content'));
                //calls SC.ArrayController.removeObject()
            }
        })
    })
})

Nicolas BADIA

unread,
Apr 24, 2013, 7:04:25 PM4/24/13
to sproutc...@googlegroups.com
Hi 
If you use master, try setting isReusable to false on your exampleView:

exampleView: SC.View.design(SC.StaticLayout, {
   isReusable: false,
            useStaticLayout: YES,
            ...

If you don't use master, I know this commit https://github.com/sproutcore/sproutcore/commit/0cc1424e00a69d08f747e40cf155e4b09e0ca301 fix an issue which could be related with your problem.


----
Nicolas



--
You received this message because you are subscribed to the Google Groups "SproutCore Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sproutcore-de...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Amilie Napier

unread,
Apr 25, 2013, 2:07:39 PM4/25/13
to sproutc...@googlegroups.com
I updated stacked.js and added isReusable:false to my view, but unfortunately that didn't fix it. Thanks for the suggestion though. I'll look through master and see if there are any other bug fixes that could help me.

Amilie

Umberto Nicoletti

unread,
Apr 26, 2013, 2:26:14 AM4/26/13
to sproutc...@googlegroups.com
Had the same issue recently, I fixed it by calling reload on the StackedView after deleting the item:

contentView.reload();

I can share the changeset, if needed.

HTH,
Umberto

Amilie Napier

unread,
Apr 26, 2013, 2:55:24 PM4/26/13
to sproutc...@googlegroups.com
Thanks Umberto, that worked!

For future reference, here's the functional code:

collection: SC.ScrollView.design({
    contentView: SC.StackedView.design({
        contentBinding: 'MyListContentController.arrangedObjects',
        exampleView: SC.View.design(SC.StaticLayout, {
            useStaticLayout: YES,
            childViews: 'data deleteButton'.w(),
            data: SC.TextFieldView.design({
                //........
            }),
            deleteButton: SC.ButtonView.extend({
                //........
                action: 'removeEntry'
            }),
            removeEntry: function () {
                MyListContentController.removeObject(this.get('content'));
                //calls SC.ArrayController.removeObject()
                this.getPath('parentView').reload();
            }
        })
    })
})
Reply all
Reply to author
Forward
0 new messages