相关疑难解决方法(0)

在ember-data中保留父级和嵌入式记录

我有以下型号:

App.Company = DS.Model.extend({
  name:  DS.attr('string'),
  accounts: DS.hasMany('App.Account', {
    inverse: 'company'
  })
});

App.Account = DS.Model.extend({
  login:                 DS.attr('string'),
  first_name:            DS.attr('string'),
  last_name:             DS.attr('string'),
  email:                 DS.attr('string'),
  password:              DS.attr('string'),
  password_confirmation: DS.attr('string'),
  company:               DS.belongsTo('App.Company')
});
Run Code Online (Sandbox Code Playgroud)

该公司被定义为嵌入在帐户中:

DS.RESTAdapter.map('App.Account', {
  company: { embedded: 'always' }
});
Run Code Online (Sandbox Code Playgroud)

当我创建一个新帐户时,公司数据正确嵌入到帐户数据中,我看到了我期望在服务器端发出的POST请求:

Started POST "/accounts" for 127.0.0.1 at 2013-06-27 13:30:53 +0200
Processing by AdminUsersController#create as JSON
  Parameters: {"account"=>{"login"=>"fsdfdf", "first_name"=>"fgdfgh", "last_name"=>"fsfdsfdsfsd@fgfdgdfgf.de", "email"=>"dsfdsgds@frgdfgfgdfg.de", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "company"=>{"name"=>"gfdhgtrhzrh"}}}
Run Code Online (Sandbox Code Playgroud)

但是,我也看到了公司本身的额外POST请求:

Started POST "/companies" for 127.0.0.1 at 2013-06-27 13:30:53 +0200
Processing by CompaniesController#create as JSON
  Parameters: {"company"=>{"name"=>"gfdhgtrhzrh"}} …
Run Code Online (Sandbox Code Playgroud)

ember.js ember-data

17
推荐指数
1
解决办法
452
查看次数

如何将多个内容生成到ember.js组件模板中?

目标是定义HTML结构,该结构具有由调用者声明的多个内容块.例如,标题,正文和内容.生成的标记应该是:

<header>My header</header>
<div class="body">My body</div>
<footer>My footer</footer>
Run Code Online (Sandbox Code Playgroud)

实例化的组件的模板将定义这三个部分,My header,My body,和My footer.

使用Ruby on Rails,您将使用content_for :header从调用者捕获标头内容并yield :header进行插值.

这可能在ember.js中吗?

handlebars.js ember.js htmlbars

16
推荐指数
2
解决办法
5921
查看次数

EmberJS多产量助手

我有一个我在Ember创建的自定义视图.我真的很喜欢{{yield}}帮助我控制三明治的"面包".然而,我现在要做的是创建一个"双层"三明治,并且其中有一个超过1个产量的视图,或者至少能够参数化第二个产量中使用的模板.

例如:

layout.hbs

<div>
    <div class="header">Header Content</div>
    <div class="tab1">
        Tab 1 Controls.
        <input type="text" id="common1" />
        {{yield}}
    </div>
    <div class="tab2">
        Tab 2 Controls.
        <input type="text" id="common2" />
        {{yield second-template}} or {{template second-template}}
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

app.js

App.MyDoubleDeckerView = Ember.View.extend({
    layoutName:"layout',
    templateName:"defaultTemplate", 
    "second-template":"defaultSecond"
});

App.MyExtendedDoubleDecker = App.MyDoubleDeckerView({
    templateName:"myTemplate", 
    "second-template":"mySecondTemplate"
});
Run Code Online (Sandbox Code Playgroud)

做这样的事有什么办法吗?我喜欢ember中的观点是能够集中和扩展视图,这使我能够在一个地方保留所有视图中共同的东西......

templates yield ember.js

6
推荐指数
1
解决办法
1284
查看次数