Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do you bind the SC.Record.toMany() data of a SC.Record to a ListView?
    primarykey
    data
    text
    <p>I am attempting to render a UI using Sproutcore where I have a list of lists. There is a vertical list of data where each associated item has a list of items of its own. I've setup the models as I believe is appropriate based on what I know of Sproutcore.</p> <p>Model:</p> <pre><code>App.VerticalData = SC.Record.extend({ someField: SC.Record.attr(Boolean), associatedListOfData: SC.Record.toMany("App.HorizontalData", { inverse: "vertical", isMaster: YES }) }); App.HorizontalData = SC.Record.extend({ someForeignKeyField: SC.Record.attr(Number), vertical: SC.Record.toOne("App.VerticalData", { inverse: "associatedListOfData", isMaster: NO }), }); </code></pre> <p>I've added a subView to the ListItemView of the vertical list and modified the subclass so that it will layout the items in the horizontal list...well...horizontally. The issue I have is that the only way I seem to be able to get the data from the toMany() relationship to bind to this horizontal list is to do the following for each item in the vertical list.</p> <pre><code>horizontalListView.set('content', App.store.find(SC.Query.local(App.HorizontalData, { conditions: 'someForeignKeyField = ' + keyValueOfVerticalItem) }))); </code></pre> <p>This is painfully, woefully slow. I don't understand why I can't seem to just use the results of the calculated property for the toMany() field for the current vertical list item. Can someone provide some guidance here? Perhaps I'm missing something silly.</p> <p>If I try to access the property directly, this is the result I get back:</p> <pre><code>Object SproutCore18001994610927067697: "sc1271" __sc_super__: Object _bindings: Array[0] _kvo_cacheable: true _kvo_changeLevel: 0 _kvo_changes: null _kvo_cloned: Object _kvo_content_observed_keys: Object _kvo_dependents: Object _kvo_revision: 2 _object_toString: "SC.ManyArray:sc1271" _observableInited: true _observers: Array[0] _prevStoreIds: Array[167] _properties: Array[15] _records: null bindings: Array[0] manyAttribute: Object outlets: Array[0] propertyName: "associatedListOfData" propertyRevision: 2 record: Object recordType: App.HorizontalData __proto__: Object </code></pre> <p>I don't know if this looks <em>correct</em> or not. So it is possible that I've got something still not defined properly in the FIXTURES I've used for my test data. The information I put in the associcatedListOfData field is an array of numbers that align to the GUIDs for the elements in the HorizontalData table.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload