2016-09-22 9 views
0

이 경우 잘못된 정보를 찾는 사람이 있는지 궁금합니다./Marionette.js - 잡히지 않은 ReferenceError : 텍스트가 정의되지 않았습니다.

var Marionette = require('backbone.marionette'); 
var TodoView = require('./views/layout'); 

var initialData = { 
    items: [ 
    {assignee: 'Scott', text: 'Write a book about Marionette'}, 
    {assignee: 'Andrew', text: 'Do some coding'} 
    ] 
}; 


var App = new Marionette.Application({ 
    onStart: function(options) { 
    var todo = new TodoView({ 
     collection: new Backbone.Collection(options.initialData.items), 
     model: new ToDoModel() 
    }); 
    todo.render(); 
    todo.triggerMethod('show'); 
    } 
}); 

App.start({initialData: initialData}); 

전망

var Backbone = require('backbone'); 
var Marionette = require('backbone.marionette'); 
var ToDoModel = require('../models/todo'); 

var FormView = require('./form'); 
var ListView = require('./list'); 


var Layout = Marionette.View.extend({ 
    el: '#app-hook', 

    template: require('../templates/layout.html'), 

    regions: { 
    form: '.form', 
    list: '.list' 
    }, 

    collectionEvents: { 
    add: 'itemAdded' 
    }, 

    onShow: function() { 
    var formView = new FormView({model: this.model}); 
    var listView = new ListView({collection: this.collection}); 

    this.showChildView('form', formView); 
    this.showChildView('list', listView); 
    }, 

    onChildviewAddTodoItem: function(child) { 
    this.model.set({ 
     assignee: child.ui.assignee.val(), 
     text: child.ui.text.val() 
    }, {validate: true}); 

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

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

module.exports = Layout; 
을 layout.js : 라인 6 app.js에서 "텍스트가 정의되어 있지 catch되지 않은 오류 ReferenceError을"

((__t=(text))==null?'':_.escape(__t))+ 

driver.js를 내가 얻을

todoitem.html

<%- item.text %> &mdash; <%- item.assignee %> 

텍스트가 정의되지 않은 이유는 무엇입니까?

+0

밑줄의 템플릿 오류처럼 보입니다. 아마도 여러분은 html 템플릿 어딘가에서'<%= text %> '과 같은 것을 사용하고 있고 올바른 데이터를 컴파일 된 템플릿에 전달하지 않는다는 것을 의미합니다. –

+0

질문이 업데이트되었습니다 : itemlist.html 템플릿에 출력이 추가되었습니다. – dev85

답변

0

맞춤 설정 데이터로 템플릿을 렌더링하는 방법을 설명하는 Marionnette의 ItemView documentation을 살펴 봐야합니다.

var my_template_html = '<div><%= args.name %></div>' 
var MyView = Marionette.ItemView.extend({ 
    template : function(serialized_model) { 
    var name = serialized_model.name; 
    return _.template(my_template_html)({ 
     name : name, 
     some_custom_attribute : some_custom_key 
    }); 
    } 
}); 

new MyView().render(); 

Note that using a template function allows passing custom arguments into the .template function and allows for more control over how the .template function is called.

현재 제공하신 코드를 사용하면 도움이되지 않습니다.

+0

ItemView의 templateHelper로 시도 할 수 있습니다.이 뷰는 모든 렌더링을 실행할 함수이고 모델에 포함되기를 원하지 않습니다. – azibi

0

마리온이 'template'에 컨텍스트를 전달하기 전에 'serializeModel'을 호출합니다. 당신이

{ 
    . 
    . 
    . 
    attributes: { 
     text: 'someText', 
     asignee: 'someAsignee' 
    } 
    . 
    . 
} 

같은 backbone.model이있는 경우 그래서, 템플릿은

{ 
    text: 'someText', 
    assignee: 'someAsignee' 
} 

내가 핸들 일한 전달되지만 정확하게 강조하지. 거기에 {{this.text}}{{this.assignee}}은 템플릿의 매력처럼 작동합니다. 그 오타에 대한 귀하의 ToDoModel을 확인

1

작동한다면, 참조 item.text 대신에 this.text 또는 text을 시도 마리오네트보기 "를 찾는 템플릿 구문 분석하는 동안, 백본 모델 필드는"기본값 "없습니다"기본 "해야한다 기본값은 "필드 :

https://marionettejs.com/docs/master/template.html#rendering-a-model

이 때문에 ToDoModel 코드는 다음과 같이 가야한다 :

... 
 

 
var ToDo = Backbone.Model.extend({ 
 
    defaults: { 
 
     assignee: '', 
 
     text: '' 
 
    }, 
 
    
 
...
,536,

관련 문제