Created
March 6, 2012 15:34
-
-
Save cronco/1986823 to your computer and use it in GitHub Desktop.
sproutcore issue - availableList contentBinding crashes app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ... */ | |
var items = Items.store.find('Items.Item'); | |
Items.selectedItemsController.set('content',[]); | |
Items.mainItemsController.set('content', items); | |
/* ... */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sc_require('controllers/selected_items'); | |
Items.mainItemsController = SC.ArrayController.create( | |
/** @scope Items.mainItemsController.prototype */ { | |
selectedBinding: 'Items.selectedItemsController.arrangedObjects', | |
arrangedObjects: function() { | |
var sel = Items.selectedItemsController.get('content'); | |
return this.filter(function(item) { | |
if (sel && sel.get('length')) { | |
return sel.indexOf(item) === -1; | |
} else return YES; | |
}); | |
}.property('content', 'selected'), | |
selectItem: function() { | |
var selected = this.get('selection').get('firstObject'); | |
console.log(selected); | |
Items.selectedItemsController.addObject(selected); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ========================================================================== | |
// Project: Items - mainPage | |
// Copyright: @2012 My Company, Inc. | |
// ========================================================================== | |
/*globals Items */ | |
// This page describes the main user interface for your application. | |
Items.mainPage = SC.Page.design({ | |
// The main pane is made visible on screen as soon as your app is loaded. | |
// Add childViews to this pane for views to display immediately on page | |
// load. | |
mainPane: SC.MainPane.design({ | |
layerId: 'items', | |
childViews: 'availableView'.w(), | |
layout: { width: 400, height: 300, centerX:0, centerY: 0 }, | |
availableView: SC.ScrollView.design({ | |
contentView: SC.View.design({ | |
layout: { maxHeight: 200, top: 0 }, | |
childViews: 'available selected'.w(), | |
available: SC.View.design({ | |
childViews: 'availableLabel availableList'.w(), | |
availableLabel: SC.LabelView.design({ | |
displayTitle: "Available Items", | |
value: "Available Items" | |
}), | |
availableList: SC.ListView.design({ | |
textAlign: SC.ALIGN_CENTER, | |
rowHeight: 10, | |
columnWidth:300, | |
contentBinding: SC.Binding.oneWay('Items.mainItemsController.arrangedObjects'), | |
selectionBinding: 'Items.mainItemsController.selection', | |
contentValueKey: 'name', | |
target: 'Items.mainItemsController', | |
action: 'selectItem', | |
}), | |
}), | |
selected: SC.View.design({ | |
layout: { top: 100, maxHeight: 200}, | |
childViews: 'selectedLabel selectedList'.w(), | |
selectedLabel: SC.LabelView.design({ | |
displayTitle: "Selected Items", | |
value: "Selected Items" | |
}), | |
selectedList: SC.ListView.design({ | |
textAlign: SC.ALIGN_CENTER, | |
rowHeight:10, | |
columnWidth: 300, | |
contentBinding:'Items.selectedItemsController.arrangedObjects', | |
contentValueKey: 'name' | |
}) | |
}) | |
}) | |
}) | |
}) | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Items.selectedItemsController = SC.ArrayController.create( | |
/** @scope Items.selectedItemsController.prototype */ { | |
orderBy: 'name' | |
}) ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment