0

我是 Backbone.js 的新手,我正在尝试构建一个 chrome 扩展来管理 github 问题。现在的问题是我没有在同一视图中获得“标题”“评论”“回购”和“受让人”和“里程碑”部分。我已经制作了两个视图,一个用于标题、评论和 repo-name,另一个用于受让人和里程碑,因为我必须获取 repo-name 才能获取受让人和里程碑。[我正在尝试将里程碑和受让人功能添加到https:// github.com/rainforestapp/github-chrome ]。

这是 view.js 的主要部分:

NewIssueView.prototype.onSubmit = function(e) {
  var func, name, repository;
  e.preventDefault();
  name = this.$("[name=repository]").val();
  localStorage['new_issue_last_repo'] = name;
  repository = this.repositories.find(function(r) {
    return r.get('full_name') === name;
  });
  window.assigneec = new ContributorCollection({
    'repo': name
  });
  window.milestonec = new MilestoneCollection({
    'repo': name
  });
  window.th = this.$el;
  window.body = this.$("[name=body]").val();
  window.title = this.$("[name=title]").val();
  window.repository = repository;
  window.temp1 = 0;
  window.temp2 = 0;
  window.assigneec.fetch({
    success: function() {
      return window.temp1 = 1;
    }
  });
  window.milestonec.fetch({
    success: function() {
      return window.temp2 = 1;
    }
  });
  func = function() {
    if (window.temp1 === 1 && window.temp2 === 1) {
      this.newIssueView = new NewIssueView({
        repository: window.assigneec
      });
      //window.th.html(this.newIssueView2.el);
      //console.log(this.newIssueView2.el);
      //this.newIssueView2.render();
      //return window.temp1 = 0;
    }
  };
  return setInterval(func, 500);
};

和模板.js

window.HAML['new2_issue'] = function(context) {
    return (function() {
      var $c, $e, $o, full_name, repository, _i, _j, _len, _len1, _ref, _ref1;
      $e = function(text, escape) {
        return ("" + text).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/'/g, '&#39;').replace(/\//g, '&#47;').replace(/"/g, '&quot;');
      };
      $c = function(text) {
        switch (text) {
          case null:
          case void 0:
            return '';
          case true:
          case false:
            return '' + text;
          default:
            return text;
        }
      };
      $o = [];
      $o.push("<div class='message'></div>\n<form>\n  <section class='assignee-select'>\n    <label for='assignee'>Assignee:</label>\n    <select class='assignee_select' name='assignee'>");
      _ref = this.repository.models;
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
        repository = _ref[_i];
        full_name = repository.get('login');
        $o.push("      <option value='" + ($c(full_name)) + "'>" + ($e($c(repository.get('login')))) + "</option>");
      }
      $o.push("    </select>\n  </section>\n  <section class='milestone-select'>\n    <label for='milstone'>Milestones:</label>\n    <select class='milestone_select' name='milestone'>");
      _ref1 = this.milestones.models;
      for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
        repository = _ref1[_j];
        full_name = repository.get('title');
        $o.push("      <option value='" + ($c(full_name)) + "'>" + ($e($c(repository.get('title')))) + "</option>");
      }
      $o.push("    </select>\n  </section>\n  <section>\n    <input class='submit' type='submit' value='Create Issue'>\n  </section>\n</form>");
      return $o.join("\n").replace(/\s(\w+)='true'/mg, ' $1').replace(/\s(\w+)='false'/mg, '').replace(/\s(?:id|class)=(['"])(\1)/mg, "");
    }).call(context);
  };

}).call(this);
(function() {
  if (window.HAML == null) {
    window.HAML = {};
  }

  window.HAML['new_issue'] = function(context) {
    return (function() {
      var $c, $e, $o, full_name, repository, _i, _j, _len, _len1, _ref, _ref1;
      $e = function(text, escape) {
        return ("" + text).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/'/g, '&#39;').replace(/\//g, '&#47;').replace(/"/g, '&quot;');
      };
      $c = function(text) {
        switch (text) {
          case null:
          case void 0:
            return '';
          case true:
          case false:
            return '' + text;
          default:
            return text;
        }
      };
      $o = [];
      $o.push("<div class='message'></div>\n<form>\n  <section class='repo-select'>\n    <select class='repo_select' name='repository'>");
      _ref = this.repositories.models;
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
        repository = _ref[_i];
        full_name = repository.get('full_name');
        //console.log(full_name);
        if (localStorage['new_issue_last_repo'] === repository.get('full_name')) {
          $o.push("      <option value='" + ($c(full_name)) + "' selected='selected'>" + ($e($c(repository.get('full_name')))) + "</option>");
        } else {
          $o.push("      <option value='" + ($c(full_name)) + "'>" + ($e($c(repository.get('full_name')))) + "</option>");
        }
      }window.HAML['new2_issue'] = function(context) {
    return (function() {
      var $c, $e, $o, full_name, repository, _i, _j, _len, _len1, _ref, _ref1;
      $e = function(text, escape) {
        return ("" + text).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/'/g, '&#39;').replace(/\//g, '&#47;').replace(/"/g, '&quot;');
      };
      $c = function(text) {
        switch (text) {
          case null:
          case void 0:
            return '';
          case true:
          case false:
            return '' + text;
          default:
            return text;
        }
      };
      $o = [];
      $o.push("<div class='message'></div>\n<form>\n  <section class='assignee-select'>\n    <label for='assignee'>Assignee:</label>\n    <select class='assignee_select' name='assignee'>");
      _ref = this.repository.models;
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
        repository = _ref[_i];
        full_name = repository.get('login');
        $o.push("      <option value='" + ($c(full_name)) + "'>" + ($e($c(repository.get('login')))) + "</option>");
      }
      $o.push("    </select>\n  </section>\n  <section class='milestone-select'>\n    <label for='milstone'>Milestones:</label>\n    <select class='milestone_select' name='milestone'>");
      _ref1 = this.milestones.models;
      for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
        repository = _ref1[_j];
        full_name = repository.get('title');
        $o.push("      <option value='" + ($c(full_name)) + "'>" + ($e($c(repository.get('title')))) + "</option>");
      }
      $o.push("    </select>\n  </section>\n  <section>\n    <input class='submit' type='submit' value='Create Issue'>\n  </section>\n</form>");
      return $o.join("\n").replace(/\s(\w+)='true'/mg, ' $1').replace(/\s(\w+)='false'/mg, '').replace(/\s(?:id|class)=(['"])(\1)/mg, "");
    }).call(context);
  };

}).call(this);
(function() {
  if (window.HAML == null) {
    window.HAML = {};
  }

  window.HAML['new_issue'] = function(context) {
    return (function() {
      var $c, $e, $o, full_name, repository, _i, _j, _len, _len1, _ref, _ref1;
      $e = function(text, escape) {
        return ("" + text).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/'/g, '&#39;').replace(/\//g, '&#47;').replace(/"/g, '&quot;');
      };
      $c = function(text) {
        switch (text) {
          case null:
          case void 0:
            return '';
          case true:
          case false:
            return '' + text;
          default:
            return text;
        }
      };
      $o = [];
      $o.push("<div class='message'></div>\n<form>\n  <section class='repo-select'>\n    <select class='repo_select' name='repository'>");
      _ref = this.repositories.models;
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
        repository = _ref[_i];
        full_name = repository.get('full_name');
        //console.log(full_name);
        if (localStorage['new_issue_last_repo'] === repository.get('full_name')) {
          $o.push("      <option value='" + ($c(full_name)) + "' selected='selected'>" + ($e($c(repository.get('full_name')))) + "</option>");
        } else {
          $o.push("      <option value='" + ($c(full_name)) + "'>" + ($e($c(repository.get('full_name')))) + "</option>");
        }
      }

如何在同一页面上组合这两个视图(或如何实现这些功能)。提前致谢。

4

0 回答 0