我正在研究概念驗證演示,並且需要編寫一個表單視圖,以便將項目添加到我的內容數組中。我從外部加載這個視圖,然後使用Handlers編譯它。我添加了一個提交方法並使用{{action}}綁定,但每次點擊提交按鈕時,它都會重新加載頁面。我錯過了什麼?使用Ember.js編寫和提交表單視圖
//模板
<form>
<div>
<label for="client">Client Name</label>
<input type="text" id="client" placeholder="Add client name" />
</div>
<div>
<button {{action "addClientSubmit" target="PM.addClientView"}}>Add Client</button>
</div>
<div>
<a href="#" {{action "closeWindow" target="PM"}}>close</a>
</div>
</form>
//視圖代碼
PM.addClientView = Ember.View.create({
templateName: 'addClient',
classNames: 'overlay',
addClientSubmit: function(e){
e.preventDefault();
console.log('submitting add client form');
console.log(a,b,c)
}
});
//最後這裏就是我如何將它添加到頁面
PM = Ember.Application.create({
loadView: function(view){
$.ajax({
url: viewPath,
success: function (template) {
if (!Ember.TEMPLATES[templateName]) {
Ember.TEMPLATES[templateName] = Ember.Handlebars.compile(template);
};
PM[view + 'View'].appendTo('body');
}
});
}
});
其他一切工程,但當我點擊提交按鈕頁面重新加載。我確定我會把東西丟掉,但我無法弄清楚它是什麼。