Skip to content

Instantly share code, notes, and snippets.

@cronco
Created March 6, 2012 15:34
Show Gist options
  • Save cronco/1986823 to your computer and use it in GitHub Desktop.
Save cronco/1986823 to your computer and use it in GitHub Desktop.
sproutcore issue - availableList contentBinding crashes app
/* ... */
var items = Items.store.find('Items.Item');
Items.selectedItemsController.set('content',[]);
Items.mainItemsController.set('content', items);
/* ... */
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);
}
});
// ==========================================================================
// 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'
})
})
})
})
})
});
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