我有一个成员应用程序,它有一个profiles路径显示一个标题和一个特定项目的描述从数据库。我想为这些数据创建一个edit页面,就像成员中的CRUD一样。我在edit资源路由下实现了一个profiles路由。
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 onyl时,将显示没有数据的表单:
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);
}
});
}
});我想在表单提交时创建一个操作,然后触发编辑操作并在服务器上执行put操作,我在服务器上有php 4后端来处理请求RESTfully。
我试图在编辑模板下实现上面的代码,就像在概要文件/编辑模板中一样,但是我无法使它工作,所以我将代码粘贴到概要文件的索引模板中。
成员在控制台上显示此日志。
生成的-> route:profiles.index对象{fullName:"route:profiles.index"}成员-1.0.0.js:356 使用默认视图<(Ember.View的子类):ember330>对象{fullName:“视图:应用程序”}成员-1.0.0.js:356呈现应用程序 使用默认视图对象{fullName:“视图:配置文件”}成员-1.0.0.js:356呈现配置文件 生成的-> controller:profiles.index对象{fullName:"controller:profiles.index"}成员-1.0.0.js:356 找不到"profiles.index“模板或视图。没有任何对象{fullName:"template:profiles.index"}成员-1.0.0.js:356 生成的->路由:索引对象{fullName:“路由:索引”}成员-1.0.0.js:356 生成的-> route:about.index对象{fullName:"route:about.index"}成员-1.0.0.js:356
发布于 2013-10-24 14:33:41
几件事:
我认为一旦你按照第1点改变,它就会正常工作。试试看。
https://stackoverflow.com/questions/19566279
复制相似问题