首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ember编辑模板

Ember编辑模板
EN

Stack Overflow用户
提问于 2013-10-24 12:42:38
回答 1查看 266关注 0票数 1

我有一个成员应用程序,它有一个profiles路径显示一个标题和一个特定项目的描述从数据库。我想为这些数据创建一个edit页面,就像成员中的CRUD一样。我在edit资源路由下实现了一个profiles路由。

index模板工作良好,它成功地填充了数据库中的数据,并在模板中显示了结果。但是,一旦我为该路由声明了一个控制器并向该控制器添加了一个操作,模板就会中断。

这是应用程序的app.js代码。

代码语言:javascript
复制
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代码:

代码语言:javascript
复制
<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时,将显示没有数据的表单:

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

发布于 2013-10-24 14:33:41

几件事:

  1. 要将其放入配置文件/编辑模板中,您需要定义具有{{edit}}的profiles.hbs模板。这样,编辑模板就会显示出来。另外,profiles.hbs应该在概要文件目录之外。概要文件目录应该包含索引和编辑模板。
  2. 我认为它应该是一个ArrayController,而不是仅仅是控制器。

我认为一旦你按照第1点改变,它就会正常工作。试试看。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19566279

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档