Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/430.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未捕获引用错误:未定义高度-Backbone.js_Javascript_Jquery_Html_Backbone.js - Fatal编程技术网

Javascript 未捕获引用错误:未定义高度-Backbone.js

Javascript 未捕获引用错误:未定义高度-Backbone.js,javascript,jquery,html,backbone.js,Javascript,Jquery,Html,Backbone.js,首先,我对Backbone.js完全陌生,我正在学习 我试图从文本输入中获取值,并从输入中创建模型。应加载模板,并且每个模型的属性高度应显示在相同的HTML上 我能够创建模型并将它们添加到集合中,因为我在console.log(部分)中看到n{length:105,models:Array[105],_byId:Object}。然而,(我猜)当我尝试加载模板时,它给了我一个错误:“uncaughtreferenceerror:height未定义”。我在想,如果我得到的属性不正确 任何帮助都将不胜

首先,我对Backbone.js完全陌生,我正在学习

我试图从文本输入中获取值,并从输入中创建模型。应加载模板,并且每个模型的属性<代码>高度应显示在相同的HTML上

我能够创建模型并将它们添加到集合中,因为我在console.log(部分)中看到
n{length:105,models:Array[105],_byId:Object}
。然而,(我猜)当我尝试加载模板时,它给了我一个错误:“uncaughtreferenceerror:height未定义”。我在想,如果我得到的属性不正确

任何帮助都将不胜感激!先谢谢你

以下是模板:

<script type="text/template" id="section-template">
    <div class="view">
       <label><%- height %></label>
       <label><%- color %></label>
       <a class="destroy"></a>
    </div>
</script>
模型集合:

var SectionList = Backbone.Collection.extend({
    model: Section,
    localStorage: new Backbone.LocalStorage("sections-backbone")
});
var Sections = new SectionList;
模型视图和事件操作:

var SectionView = Backbone.View.extend({
    tagName:  "li",
    template: _.template($("#section-template").html()),
    initialize: function() {
    },
    render: function() {
        this.$el.html(this.template(this.model.toJSON()));
        return this;
    }
});
申请:

var AppView = Backbone.View.extend({
    el: $("#sectionboard"),
    events: {
        "keypress #new-height":  "createOnEnter"
    },
    initialize: function() {
        this.input = this.$("#new-height");
        this.main = $("#main");
        Sections.fetch();
    },
        createOnEnter: function(e) {
         if (e.keyCode != 13) return;
         if (!this.input.val()) return;
         Sections.create({height: this.input.val(), color: '#FFFFFF'});
         this.input.val("");

         console.log(Sections);

         var view = new SectionView({model: Sections});
         this.$("#section-list").append(view.render().el);

      }
});
var App = new AppView;

我认为问题就在这里

var view = new SectionView({model: Sections});

Sections
是一个集合,但您告诉视图它是一个模型,因此存在冲突

要表示问题已解决,请接受解决问题的答案,而不是更新title@Tholle就这么做了。谢谢你的提示!:)@Thole很感激,我讨厌乞求分数。阿尔文:用主干网玩得很开心,我已经用了几个星期了,它真的很棒。
var view = new SectionView({model: Sections});