Backbone.js は初めてで、github の問題を管理するためにクロム拡張機能を構築しようとしています。問題は、同じビューで「タイトル」「コメント」「レポ」「担当者」「マイルストーン」セクションが表示されないことです。担当者とマイルストーンを取得するためにレポ名を取得する必要があったため、タイトル、コメント、レポ名用と担当者とマイルストーン用の 2 つのビューを作成しました。 [マイルストーンと担当者機能を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);
};
およびtemplate.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, '&').replace(/</g, '<').replace(/>/g, '>').replace(/'/g, ''').replace(/\//g, '/').replace(/"/g, '"');
};
$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, '&').replace(/</g, '<').replace(/>/g, '>').replace(/'/g, ''').replace(/\//g, '/').replace(/"/g, '"');
};
$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, '&').replace(/</g, '<').replace(/>/g, '>').replace(/'/g, ''').replace(/\//g, '/').replace(/"/g, '"');
};
$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, '&').replace(/</g, '<').replace(/>/g, '>').replace(/'/g, ''').replace(/\//g, '/').replace(/"/g, '"');
};
$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>");
}
}
この 2 つのビューを同じページに組み合わせる方法 (またはこれらの機能を実現する方法)。よろしくお願いします。