English 中文(简体)
未能从收集角度正确通过模型?
原标题:Failing to pass models correctly from collection view?

我在这样做的时候 star着,试图制造各种ak子,却徒劳无益。

为什么我拿到“这......模仿是没有界定的”错误

$(function(){


  window.Sentence = Backbone.Model.extend({ 

    initialize: function() {
      console.log(this.toJSON()) 
    }
  });

  window.Text = Backbone.Collection.extend({
    model : Sentence,

    initialize: function(models, options){
      this.url = options.url;
    }
  });

  window.SentenceView = Backbone.View.extend({
    initialize : function(){
      _.bindAll(this,  render );
      this.template = _.template($( #sentence_template ).html());
    },

    render : function(){
      var rendered = this.template(this.model.toJSON());
      $(this.el).html(rendered);
      return this;
    }
  })

  window.TextView = Backbone.View.extend({
    el : $( #notebook ) ,

    initialize : function(){
      _.bindAll(this,  render );
    },

    render : function(){
      this.collection.each(function(sentence){
        if (sentence === undefined){
          console.log( sentence was undefined );
        };

        var view = new SentenceView({model: sentence});
        this.$( ol#sentences ).append(view.render().el);
      });

      return this;
    }
  });

  function Notebook(params){
    this.text = new Text(
      // models
      {}, 
      // params
      {
        url: params.url 
      }
    );


    this.start = function(){
      this.text.fetch();
      this.textView = new TextView({
        collection: this.text
      });
      $( body ).append(this.textView.render().el);
    };
  }

  window.notebook = new Notebook(
    {  url :  js/mandarin.js  }
  );

  window.notebook.start();

})

有一个网上版本的“you子”可以发现奥ole中的错误:

http://lotsofwords.org/English/chinese/notebook/

整个文件是:

https://github.com/amundo/notebook/

犯罪线似乎是:

我发现这种ple情,因为只要我能够把 it在<代码>上。 原文:<>。 syntax,我仅可以指出,Sentence的模型为何没有显示出应有的进展。

问题回答
var view = new SentenceView({model: sentence});

当你把数据传送给主人观构造时,数据被添加到<条码>Backbone.View.options上。

2. 改变这一方向

var rendered = this.template(this.model.toJSON());

页: 1

var rendered = this.template(this.options.model.toJSON());

并且看看它是否运作

www.un.org/Depts/DGACM/index_spanish.htm

摘自:

在形成新观点时,您通过的各种选择都附于这一意见之后,以供今后参考。 有一些特殊选择,如果通过,将直接附在以下观点:模式、收集、使用、复制、分类和标签。

因此,无视上述建议——该模式应在违约时直接附属于标的。

a. 货物在清点时检查:

  • 在<代码>render()中确认,this实际上是SentenceView标的。

  • 2. 确认你没有在这里服定的句子:

    var view = new SentenceView({model: sentence});
    

附录2:

当时,它喜欢收集:

this.textView = new TextView({
    collection: this.text
});

更不用说,你需要加以审查,并着手进行什么工作。 当我看着大火时,收集财产看上去我。

你也可以有时间问题。 我认为,这套手法不合时宜,因此,在你确信书本已经完成之前,你可能不想将书卷交给文稿。

前表强调,js为你收集方法,以便你能够这样做。 参见:

this.collection.each(function(sentence) {
  // YOUR CODE HERE
});

我认为,问题已经到了记本的第48条。 j 如下所示:

render : function(){
    _(this.collection).each(function(sentence){
    var view = new SentenceView({model: sentence});
    this.$( ol#sentences ).append(view.render().el);
}); 

问题在于你正在总结,而你却没有。 改动

this.collection.each(function(sentence){ ...

希望安定

EDIT: OK i m going to take another crack at it now that you mentioned timing in one of your comments

审视一下你在什么地方et着,并把它改为:

this.start = function(){
    this.text.fetch({
        success: _.bind( function() {
            this.textView = new TextView({
                collection: this.text
            });
            $( body ).append(this.textView.render().el);
        }, this)
    );
}; 

我用人工分类,因此可能出现错配母体。 关键是,脂肪是合成物。

希望这一解决办法

审判:

 _.each(this.collection, function(sentence){
    if (sentence === undefined){
      console.log( sentence was undefined );
    };

    var view = new SentenceView({model: sentence});
    this.$( ol#sentences ).append(view.render().el);
  },this);




相关问题
What s the appropriate granularity for Backbone.js Views?

I m adopting Backbone.js to render a small corner of an existing large web app. If this goes well, I can see Backbone.js growing to encompass the whole of the app, lending some much-needed structure ...

Rendering Layouts with Backbone.js

If you were to build a single page web application (SPWA) using Backbone.js and jQuery with--for example--two controllers that each required a unique page layouts, how would you render the layout? ...

Load html without refresh

Im unsure of how to approach this, should I have the html to be loaded hidden or load it from somewhere? I want to load a form in one page, and dynamic content on other pages. The form can be saved ...

Why are my CoffeeScript/backbone.js events not firing?

I m trying to familiarize myself with CoffeeScript and backbone.js, and I must be missing something. This CoffeeScript: MyView = Backbone.View.extend events: { "click" : "testHandler" ...