0

そのため、backbone.js コードを少し継承したので、今日変更する必要があります。元のコードを書いた人は休暇中です。私は backbone.js についてほとんど勉強していないだけで、ほとんどバックボーンの初心者です。

以下のコードは動作し、設計された目的を果たします。問題は 1 つだけです。テンプレート ファイル (以下を参照) のコンテンツが特定の HTML ページにレンダリングされます。

私の問題は、その HTML ページの実際のコンテナーへの参照を挿入する方法と場所、およびそのコンテナー内に表示するコンテンツを取得する方法について、知識に基づいた推測を行うためのコードの流れを完全に理解していないことです。

この関数からの出力が必要なコンテナーのクラス名は.mngmnt-main-sctn. これは可能ですか?

.

window.ManagementInstancesBackupView = ManagementView.extend({

  events: _.extend({
    }, ManagementView.prototype.events
  ),

  initialize: function() {
    this.model      = this.options.model
    this.collection = this.options.collection
    this.template   = _.template($('#instances-management-backup-template').html())
  },

  render: function() {
    var instances = this.collection

   // Append container and title
   var $el = this.$el.html(this.template({}))

   instances.each(function(instance) {

    //    THIS IS THE CONTAINER THAT SHOULD GET STUFF APPENDED TO:
    //    $(".mngmnt-main-sctn")


      $el.append(this.renderParent(instance));

      instance.get('nic').each(function(nic) {
        $el.append(this.renderChild(nic));
      }, this)
    }, this)

    return this
  },

  renderParent: function(instance) {
    return new ManagementInstancesBackupParentView({model: instance}).render().$el
  },

  renderChild: function(nic) {
    return new ManagementInstancesBackupChildView({model: nic}).render().$el
  }

});
4

2 に答える 2