我有一個灰燼應用程序,它有一個profiles
路徑來顯示數據庫中特定項目的標題和描述。我想爲該數據創建一個edit
頁面,如在ember中的CRUD。我在profiles
資源路由下實施了edit
路由。灰燼編輯模板
index
模板工作正常,它成功地填充數據庫中的數據,結果顯示在模板中。但是,只要我爲該路由聲明一個控制器並向該控制器添加一個操作,該模板就會中斷。
這是應用程序的app.js代碼。
App.Profile = DS.Model.extend({
title: DS.attr('string'),
description: DS.attr('string')
});
App.Router.map(function(){
this.resource("about", function(){
this.route("create", {path: '/create'});
});
this.resource('profiles', {path: '/profiles/:profiles_id'}, function(){
this.route('edit');
});
this.resource('login');
this.resource("logout");
});
App.ProfilesController = Ember.Controller.extend();
App.ProfilesRoute = Ember.Route.extend({
model: function(params) {
NProgress.start();
var data = App.Profile.find(params.profiles_id);
data.then(function(){
NProgress.done();
});
return data;
}
});
的HTML代碼的配置文件:
<script type="text/x-handlebars" data-template-name="profiles">
<div class="container">
<div class="row">
<h1>{{title}}</h1>
<p>
{{description}}
</p>
<form {{action edit on="submit"}}>
{{input value=title type="text" placeholder="Title"}}
{{textarea value=description}}
{{input class="button" type="submit" value="Edit"}}
</form>
</div>
</div>
</script>
此時一切正常。但只要我將編輯動作添加到ProfileController,當我在瀏覽器中加載頁面時,只顯示沒有數據的表單。什麼地方出了錯?
當我將此代碼添加到ProfilesController磺酰基,沒有數據的形式顯示:
App.ProfilesController = Ember.Controller.extend({
edit: function(){
var self =this, data = this.getProperties('title', 'description');
self.set('errorMessage', null);
self.set('successMsg', null);
Ember.$.put('profiles', data, function(){
NProgress.start();
}).then(function(response){
NProgress.done();
if(response.success){
}else {
self.set('errorMessage', response.message);
console.log(response.message);
}
});
}
});
我想創建一個動作,當表單提交,編輯操作被觸發並做穿上服務器,我有php laravel 4後端在服務器來處理請求RESTfully。
我試圖在配置文件/編輯模板中的編輯模板下實現上面的代碼,但我無法使它工作,所以我將代碼粘貼到配置文件的索引模板中。
灰燼顯示該日誌在控制檯上產生
- >路線:profiles.index對象{全名: 「路線:profiles.index」}燼-1.0.0.js:356
渲染應用與默認視圖<( Ember.View的子類):ember330>對象{全名: 「視圖:應用」} 燼-1.0.0.js:356個
與默認視圖 對象{全名渲染配置文件: 「視圖:輪廓」}燼-1.0.0.js:356
產生 - >控制器:profiles.index對象{全名: 「控制器:profiles.index」}燼-1.0.0.js:356
找不到「profiles.index」模板或視圖。沒有什麼會是 渲染對象{全名: 「模板:profiles.index」} 燼-1.0.0.js:356
產生 - >路線:索引對象{全名: 「路線:索引」} ember- 1.0.0.js:356
generated - > route:about.index Object {fullName:「route:about.index」} ember-1.0.0。JS:356
謝謝你的回答,但到現在爲止我還沒有使用hbs文件,我不知道如何在後端使用laravel,使用上面的代碼,請你稍微描述一下,控制器和hbs更正,你是建議? – monk
您不必使用hbs文件。基本上配置文件data-template-name應該有{{outlet}},並且您將擁有另外兩個帶有配置文件/索引和配置文件/編輯的數據模板名稱。您也可以將它們全部保存在單個文件中。 – VNarasimhaM