-
-
Save ColinCampbell/1094572 to your computer and use it in GitHub Desktop.
Nested Records
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
Authoring = SC.Application.create( | |
store: SC.Store.create().from(SC.Record.fixtures) | |
}) ; |
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
Authoring.LibraryFile = SC.Record.extend({ | |
name: SC.Record.attr(String), | |
path: SC.Record.attr(String), | |
size: SC.Record.attr(Number), | |
type: SC.Record.attr(String), | |
checksum: SC.Record.attr(String), | |
cdn: SC.Record.attr(Boolean) | |
}); |
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
Authoring.libraryFileController = SC.ArrayController.create({ | |
// you probably want a chained observer here | |
// this will fire if `content` or `content.files` changes, | |
// instead of just `content.files` | |
contentBinding: 'Authoring.libraryController*content.files' | |
}) ; |
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('models/library_model'); | |
//sc_require('models/file_model'); add here? | |
Authoring.Library.FIXTURES = [ | |
{ | |
user_id : 1, | |
name : "Justin", | |
files : [ | |
{ | |
guid : 0, | |
name : "photo1.png", | |
path : "some/path", | |
size : 26, | |
type : "image/png", | |
checksum : "", | |
cdn : false | |
}, | |
{ | |
guid : 1, | |
name : "photo2.png", | |
path : "some/path", | |
size : 14, | |
type : "image/png", | |
checksum : "", | |
cdn : false | |
}, | |
{ | |
guid : 2, | |
name : "photo3.png", | |
path : "some/path", | |
size : 12, | |
type : "image/png", | |
checksum : "", | |
cdn : false | |
}, | |
{ | |
guid : 3, | |
name : "photo4.png", | |
path : "some/path", | |
size : 4, | |
type : "image/png", | |
checksum : "", | |
cdn : false | |
}, | |
{ | |
guid : 4, | |
name : "photo5.png", | |
path : "some/path", | |
size : 18, | |
type : "image/png", | |
checksum : "", | |
cdn : false | |
}, | |
{ | |
guid : 5, | |
name : "photo6.png", | |
path : "some/path", | |
size : 12, | |
type : "image/png", | |
checksum : "", | |
cdn : false | |
} | |
] | |
} | |
]; |
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
Authoring.libraryController = SC.ObjectController.create({ | |
content: null | |
}); |
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
Authoring.Library = SC.Record.extend({ | |
primaryKey: 'user_id', | |
name: SC.Record.attr(String), | |
user_id: SC.Record.attr(Number), | |
files: SC.Record.toMany('Authoring.LibraryFile', { nested: true }) | |
}); |
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.ScrollView.design({ | |
layout: { top: 140 }, | |
contentView: SC.ListView.design({ | |
layout: { top: 0 }, | |
classNames: 'library-list', | |
actOnSelect: YES, | |
showAlternatingRows: YES, | |
rowHeight: 24, | |
contentBinding: "Authoring.libraryFileController", | |
selectionBinding: "Authoring.libraryFileController.selection", | |
contentValueKey: "name", | |
action: "fileClicked" | |
}) | |
}) |
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
// call to statechart action | |
// Here's the problem: | |
// If you look at the docs for SC.Store#find: http://docs.sproutcore.com/#doc=SC.Store&method=find&src=false | |
// You'll see that calling it without an ID parameter creates a RecordArray and returns it | |
// You're setting this to the content of an SC.ObjectController, which is expecting to proxy an object, not | |
// an array. So you're binding from Authoring.libraryController (an SC.ObjectController) to Authoring.libraryFileController | |
// which is an SC.ArrayController (this part is right). I'm suspecting you want to set the content of libraryController | |
// to an object. If you decide what your primaryKey for library is going to be (I'm assuming user_id but it can be whatever) | |
// then you just change it to load that ID. It will return an Authoring.Library object and produce the results you want! | |
Authoring.libraryController.set('content', Authoring.store.find(Authoring.Library, 1)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment