2017-11-21 3 views
1

기능을 사용하여 마리오넷에서 렌더링 할 자식 뷰를 결정하는 방법을 알아낼 수 없습니다. 여기에 문서를 기반으로 매우 간단해야처럼 보인다 : 나는 childView를 정의하는 함수를 사용하여 수집 및 복합 뷰 https://marionettejs.com/docs/master/marionette.compositeview.html#compositeviews-childview)조건부로 뷰 마리오 네트를 렌더링 할 수 없음

을위한 동일해야한다는 추론 복합 뷰 문서에서 해당 페이지를 찾을

https://marionettejs.com/docs/master/marionette.collectionview.html#collectionviews-childview

그러나 다음 코드로 "잡히지 않은 TypeError : view.on이 함수가 아닙니다."라는 오류 메시지가 나타납니다. 내 코드는 다음과 같습니다.

var Backbone = require('backbone'); 
var Marionette = require('backbone.marionette'); 

var ToDoModel = require('./models/todo'); 

var ToDo = Marionette.LayoutView.extend({ 
    tagName: 'li', 
    template: require('./templates/todoitem.hbs') 
}); 


var TodoList = Marionette.CompositeView.extend({ 
    el: '#app-hook', 
    template: require('./templates/todolist.html'), 

    childView: function(item) { 
    return ToDo; 
    }, 
    childViewContainer: 'ul', 

    ui: { 
    assignee: '#id_assignee', 
    form: 'form', 
    text: '#id_text' 
    }, 

    triggers: { 
    'submit @ui.form': 'add:todo:item' 
    }, 

    collectionEvents: { 
    add: 'itemAdded' 
    }, 

    modelEvents: { 
    invalid: 'itemInvalid' 
    }, 

    onAddTodoItem: function() { 
    this.model.set({ 
     assignee: this.ui.assignee.val(), 
     text: this.ui.text.val() 
    }); 

    if (this.model.isValid()) { 
     var items = this.model.pick('assignee', 'text'); 
     this.collection.add(items); 
    } 
    }, 

    itemAdded: function() { 
    this.model.set({ 
     assignee: '', 
     text: '' 
    }); 

    this.ui.assignee.val(''); 
    this.ui.text.val(''); 
    }, 

    itemInvalid: function() { 
    console.log('this item is invalid!') 
    } 

}); 


var todo = new TodoList({ 
    collection: new Backbone.Collection([ 
    {assignee: 'Scott', text: 'Write a book about Marionette'}, 
    {assignee: 'Andrew', text: 'Do some coding'} 
    ]), 
    model: new ToDoModel() 
}); 

todo.render(); 

왜 ToDo보기가 렌더링되지 않습니까?

+0

A [mcve를 기입하십시오 : 함수가 지원되지 않으므로 같은 마리오네트, childView의 이전 버전에서

, 대신 당신은 getChildView

그래서, 코드의 관련 부분이 보일 것입니다 사용해야합니다 ] 실행 가능한 스택 스 니펫을 사용합니다. –

답변

3

이전 버전의 Marionette (예 : LayoutView)가 버전 3에서 제거되었고 가장 최신 버전 (현재 3.5.1)의 설명서를 참조한 것처럼 보입니다.

var TodoList = Marionette.CompositeView.extend({ 
    ... 
    getChildView: function(item) { 
    return ToDo; 
    }, 
    ... 
}); 
관련 문제