当一个模型依赖于另一个模型时如何创建模型

3

我有些困惑如何在我的createRecord动作中创建一个事件,当我在路由中返回3个模型时:

return RSVP.hash({
  event: this.store.createRecord('event'),
  hiws: this.store.findAll('hiw'),
  tips: this.store.findAll('tip')
});

事件是我想要创建的,但在hiwstips中进行each循环,因为一个事件只有一个hiw和一个tip……就像这样:

<select class="tables__sidebar-select">
  {{#each model.tips as |tip|}}
    <option class="tables__sidebar-option">{{tip.name}}</option>
  {{/each}}
<select>

同样的,对于hiws也是如此。 我尝试这样做: 在我的createRecord操作中,我有:

  let hiws = this.get('model.hiws');
  let tips = this.get('model.tips');
  let notify = this.get('notify');

  let event = this.get('store').createRecord('event', {
    hiws: hiws,
    tips: tips
  });

  event.save()

我正在尝试创建一个带有所有属性以及“hiw”和“tip”的事件,但是选定的“hiw”和“tip”无效。

编辑:

现在,我正在尝试使用以下内容:

{{view "select" content=models.tips.names value=models.event.tip}}

但是没有成功。

让我看看我是否正确理解了您的意思:您有三个模型:tips、hiws和event。然后,在您的模板中,您想显示两个选择元素,一个用于tips,另一个用于hiws。当在它们中的每一个中选择一个值时,您希望将这两个值保存为事件记录。这是正确的吗? - Henry Vonfire
是的!!!我现在正在尝试跟进这个 -> http://emberjs.jsbin.com/zezapu,我可以正确地看到带有选项的选择器,但是我无法在我的 createRecord 动作中获取值 :/ @HenryVonfire - user5526811
请查看此链接 https://ember-twiddle.com/78b6a5ea8e8e84e5b2a3 - Henry Vonfire
嘿,谢谢!!!你能发布一个答案吗? - user5526811
当然,我现在会发布它 :) - Henry Vonfire
显示剩余2条评论
1个回答

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接