Comments (3)
So, having sat on this all day and thinking about it in the back of my head, I'm slowly coming to the conclusion that what I have is good enough. The amount of code that it would take to move this to the next step of having it be a self-contained hierarchy that knows how to handle the top level item whether or not a model exists, is going to push me in to diminishing returns and probably not be worth the headache that it would cause in terms of maintenance.
from backbone.marionette.
I've looked over your sample, I don't have a better suggestion (though I am still a little backbone baby).
I had a similar problem though in a non-backbone context recently. My solution was to examine the top-level item and "normalize" it to fit the pattern that the children were expected to follow. Perhaps that's what you were trying to do here (and I'm just missing it):
initialize: function(){
if (this.model){
this.collection = this.model.nodes;
}
}
Though I would have expected something more like:
initialize: function() {
var items = this.model;
if(_.isArray(item)) {
this.model = { nodes: items };
}
}
Again, I'm pretty ignorant of backbone still. I suspect it's a bad idea to clobber the model like that.
I say to move ahead with it until it hurts, and if it starts to hurt then look for a better solution.
from backbone.marionette.
moving forward with the structure as-is
from backbone.marionette.
Related Issues (20)
- Feature Request: Adding Style property HOT 2
- Fix coverage issue
- Fix coveralls issue HOT 1
- Upgrade to backbone 1.4 HOT 6
- Browser support clarification needed HOT 2
- CollectionView adding Model to collection does nothing HOT 1
- Calling getRegion can cause callstack error
- Extract jquery from the dom api and make vanilla the default
- Repeated sort and filter after addChildView HOT 9
- Coverage remained the same at 100.0% when pulling 028004a on thapaphon21731:patch-1 into 5090557 on marionettejs:master
- unbindRequests does not pass context
- CollectionView Comparator documentation is confusing when using functions HOT 1
- CollectionView does not seem to properly extend View HOT 3
- getOption falsy key behavior differs from native js object
- on upgrading v2 to v3,can not replace marionette module functionality without using webpack or browserfiy? HOT 1
- Help - Trying to update from ES5 to ES6+ and losing templateContext during rendering HOT 5
- Official docs are gone HOT 10
- Is `marionettejs.com` down? HOT 2
- Update doc links to new url HOT 1
- ui, events,regions selector doesn't scoped to current view HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from backbone.marionette.