Skip to content

Instantly share code, notes, and snippets.

@zackdouglas
Created January 5, 2012 14:00
Show Gist options
  • Save zackdouglas/1565378 to your computer and use it in GitHub Desktop.
Save zackdouglas/1565378 to your computer and use it in GitHub Desktop.
A working example of a two-teired ListView in Sproutcore 1.x (Tested in 1.6.x)
Test = SC.Application.create({ NAMESPACE: 'Test', VERSION: '0.1.0', store: SC.Store.create().from(SC.Record.fixtures) }) ;
Test.Top = SC.Record.extend({
middles: SC.Record.toMany(
SC.Record.extend({
bottoms: SC.Record.toMany(
SC.Record,
{
isNested: YES,
isMaster: NO
}
)
}),
{
isNested: YES,
isMaster: NO
}
)
});
Test.TopObjectController = SC.ObjectController.create();
Test.MiddlesArrayController = SC.ArrayController.create({
isEditable: YES,
contentBinding: 'Test.TopObjectController.middles'
});
top = Test.Top.create({ middles: [] });
Test.TopObjectController.set('content', top);
newMiddle = SC.copy({ bottoms: [] });
Test.MiddlesArrayController.addObject( newMiddle );
Test.TopView = SC.View.design({
childViews: ['middles'],
middles: SC.ListView.design({
contentBinding: 'Test.MiddlesArrayController.arrangedObjects',
exampleView: SC.View.design({
render: function () {
sc_super();
this.set('controller',
SC.ArrayController.create({
content: this.getPath('content.bottoms')
})
);
},
childViews: ['bottoms'],
bottoms: SC.ListView.design({
contentBinding: '.parentView.controller',
exampleView: SC.TextFieldView.design({
contentBinding: '.content.myField'
})
})
})
})
})
@sevifives
Copy link

Test.TopView = SC.View.design({

  childViews: ['middles'],

  middles: SC.ListView.design({

    contentBinding: 'Test.MiddlesArrayController.arrangedObjects',

    exampleView: SC.View.design({

      childViews: ['bottoms'],

      bottoms: SC.ListView.design({

        contentBinding: '.parentView*content.bottoms',

        exampleView: SC.View.extend({

          createChildViews: function () {
            var content = this.get('content');

            this._textField = this.createChildView(SC.TextFieldView, {
              contentBinding: SC.Binding.from('myField',content)
            });
            
            this.set('childViews',[this._textField]);
          }
          
        })
        
      })
      
    })
    
  })
  
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment