目录

CheckBoxes

它是一个方框,用户可以在其中打开和关闭,也就是说,它允许在两个可能的选项之一中进行选择。 复选框支持以下属性 -

  • checked
  • disabled
  • tabindex
  • indeterminate
  • name
  • autofocus
  • form

语法 (Syntax)

{{input type = "checkbox" name = "NameOfCheckBox" checked = NameOfCheckBox}}

例子 (Example)

下面给出的示例指定输入助手中复选框的用法。 创建一个名称为checkbox的路由,然后打开router.js文件以定义URL映射 -

import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend ({
   location: config.locationType,
   rootURL: config.rootURL
});
Router.map(function() {
   this.route('checkbox');
});
export default Router;

使用以下代码打开在app/templates /下创建的文件application.hbs文件 -

<h2>Input Helper CheckBox</h2>
{{#link-to 'checkbox'}}Click Here{{/link-to}}
{{outlet}}

单击链接时,页面应打开checkbox.hbs文件,其中包含以下代码 -

{{input type = "checkbox" checked = checkMe}} Check Box
<button {{action "send"}}>Click the checkbox</button>
{{outlet}}

使用以下代码打开在app/routes/下创建的checkbox.js文件 -

import Ember from 'ember';
export default Ember.Route.extend ({
   model: function () {
      return Ember.Object.create({
         checkMe: false
      });
   }
});

现在打开在app/controllers/下创建的checkbox.js文件,代码如下 -

import Ember from 'ember';
export default Ember.Controller.extend ({
   actions: {
      send: function () {
         document.write('checkbox value: ' + this.get('checkMe'));
      }
   }
});

输出 (Output)

运行ember服务器; 你会收到以下输出 -

Ember.js模板复选框

当您单击该链接时,将显示一个复选框并单击它 -

Ember.js模板复选框

接下来单击按钮,它将显示结果为true,如下面的屏幕截图所示 -

Ember.js模板复选框
↑回到顶部↑
WIKI教程 @2018