javascript - 为 Handlebars 模板中的模型赋值

标签 javascript ember.js

我正在关注 this tutorial 并且任何时候它引用输入元素时它都将它们定义为:

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

有人告诉我这已经过时了,而且文档确实没有 use that format ,而不是使用这种格式:

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

我正处于将数据保存到商店的教程中。我修改了教程以使用尖括号而不是像这样的大括号:

<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>

我的路线是这样的:

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();
    }
  }

});

当我调用路由操作 saveLibrary 并打开调试器时,newLibrary 没有来自模型属性的任何数据。每当我像教程那样更改 Handlebars 模板以使用大括号时,它都可以正常工作; newLibrary 包含name, address & phone.

使用 Angular 括号并将其传播到 route.js 的语法是什么?

最佳答案

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

关于javascript - 为 Handlebars 模板中的模型赋值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56689480/

相关文章:

javascript - 如果我在回调中不使用 `this` 关键字,是否应该使用可选的上下文参数?

javascript - B 做某事时如何更改 A 的 html 站点

javascript - 如何更新不可变列表以获取新列表

ember.js - 如何编写模块化 Ember.js 应用程序

ember.js - 如何在 Handlebars (Ember.js) 模板的 #each 循环中使用 holder.js?

javascript - 在 jquery-ui.min.js 之前包含 jquery.min.js 的顺序很重要吗?

Javascript 将日期和时间添加到 mailto 主题链接

javascript - Babel 取消了 ember.js 应用程序中大文件的样式优化

Javascript/Ember - 切换变量的 boolean 值

ember.js - 在计算属性中使用 this.store.query()