私は現在2つのビューを持っています。1 つは mongoDb オブジェクトのコレクションをリストし、もう 1 つは er の編集を許可することになっています。リスト ビューは問題なく動作しますが、編集ビューをレンダリングしようとすると、次のエラーが発生します。
Uncaught SyntaxError: Unexpected identifier
失敗したコードは次のとおりです (Underscore.js の 1155 行目)。
try {
render = new Function(settings.variable || 'obj', '_', source);
Uncaught SyntaxError: Unexpected identifier
} catch (e) {
e.source = source;
throw e;
}
そして、上記のコードを実行させる私のコードは次のとおりです。
render : function(){
var id = glob;
var skill = new SkillModel({_id:id});
skill.fetch();
console.log("BLAH");
var template = _.template($('#editTemplate').html(), {skill: {name:"Test", value:"Value", id:"123"}});
this.$el.html(template);
return this;
}
次の行が見つかりました:
var template = _.template($('#editSkillTemplate').html(), {});
それを引き起こす行です。奇妙なことに、私は listView render 関数と同じようにすべてを行ったので、何が問題なのかわかりません。参考までに、リスト ビューのコードを次に示します。
render : function(){
var that = this;
var skillset = new SkillSet();
skillset.fetch({success: function(model, result){
var template = _.template($('#skillsTemplate').html(), {items: result });
that.$el.html(template);
}})
return this;
}
テンプレートは次のとおりです。
<script type="text/template" id="editTemplate">
<section>
<form id="editForm">
<label for="skillName"><input id="skillName" type="text" value="<%= skill.name %>" />
<br />
<label for="skillValue"><input id="skillValue" type="text" value="<%= skill.value $>" />
<br />
<a href="#/save/<%= skill.id %>"><button class="save">Save</button></a>
<a href="#/delete/<%= skill.id %>"><button class="delete">Delete</button></a>
</form>
</section>
</script>