简体   繁体   English

为手柄模板中的模型指定值

[英]Assigning value to a model in a handlebars template

I'm following this tutorial and any time it references an input element it defines them as so: 我正在学习教程,并且只要它引用了一个输入元素,它就会定义它们:

{{input type="text action='actionname'... }}

I'm told this is out of date and indeed the docs don't use that format , instead using this format: 我被告知这已经过时了,实际上文档并没有使用那种格式 ,而是使用这种格式:

<input type="text" {{action 'actionname' ... }}

I'm at the point of the tutorial where I'm saving data to the store. 我正在教程中我将数据保存到商店。 I've amended the tutorial to use angle brackets instead of curly braces like so: 我修改了教程,使用尖括号代替花括号,如下所示:

<input type="text" value={{model.name}} class="form-control" placeholder="The name of the Library" />
<input type="text" value={{model.address}} class="form-control" placeholder="The address of the Library" />
<input type="text" value={{model.phone}} class="form-control" placeholder="The phone number of the Library" />
<button type="submit" class="btn btn-default" {{action 'saveLibrary' model}}>Add to library list</button>

My route looks like: 我的路线看起来像:

import Route from '@ember/routing/route';

export default Route.extend({

  model() {
    return this.store.createRecord('library');
  },

  actions: {
    saveLibrary(newLibrary) {
      newLibrary.save().then(() => this.transitionTo('libraries'));
    },

    willTransition() {
      this.controller.get('model').rollbackAttributes();
    }
  }

});

When I call the route action saveLibrary and open the debugger, newLibrary doesn't have any data from the model properties. 当我调用route action saveLibrary并打开调试器时, newLibrary没有来自模型属性的任何数据。 Whenever I change the handlebars template to use curly braces like the tutorial, it works fine; 每当我改变把手模板以使用像教程一样的花括号时,它工作正常; newLibrary contains name , address & phone . newLibrary包含nameaddressphone

What is the syntax for using angle brankets and having it propagate to route.js ? 使用角度分支并将其传播到route.js的语法是什么?

尖括号组件应为<Input>而不是<input>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM