문제

I'm creating a backbone view for displaying a list of folders created by user in my webapp. but I want to have a default entry like no folder to be displayed in the list as well. Instead of inserting the DOM inside the view, I want to just add a model to the collection which does not get synced to server but is just used to be rendered in the view.

Is there a way I can do this? I tried this an failed...

var def = {'name': 'none', 'selected': 'true'};
var coll = new app([def]);

// model here
var appitem = Backbone.Model.extend({
    defaults: {
        name: '',
        id: '',
        selected: 'false'
    }
});

// collection here
app = Backbone.Collection.extend({
    model: appitem,
    url: '/apps'
});
도움이 되었습니까?

해결책

You should not alter your models based on what the view needs.

If you need to display a 'no folder' entry, than it belongs in the view.

Don't complicate your life by adding data without meaning to the model layer. Keep it in the view.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top