Ember.js Ember.Templates.helpers hash()方法

Ember.js Ember.Templates.helpers hash()方法

Ember.js 是一个基于MVC架构的开源JavaScript框架,用于开发大型客户端Web应用程序。Ember.js是最常用的前端应用程序框架之一。它旨在加快开发速度,提高生产力。目前,许多网站都在使用它,包括Square、Discourse、Groupon、Linked In、Live Nation、Twitch和Chipotle。

hash() 方法创建一个哈希对象,用作组件选项的参数。

语法:

hash( options )

参数:

  • options: 它是传递给组件的对象。

返回值: 对象哈希。

安装和运行 Ember.js 的步骤:

步骤1: 要运行以下示例,您需要拥有一个 Ember 项目。要创建一个项目,您需要首先安装 ember-cli。在终端中编写以下代码:

npm install ember-cli

步骤2: 现在,您可以通过输入以下代码来创建项目:

ember new <project-name> --lang en

要启动服务器,请键入:

ember serve

示例1: 输入以下代码以生成此示例的路线:

ember generate route hash

app/components/compact.hbs

<h2> 
    {{@a.Name}} has skill in {{@a.lan}} language.  
</h2>

app/templates/hash.hbs

<h1> 
    Introduction of Student:  
</h1> 
<Compact @a={{hash Name='Aayush' Age='JavaScript'}}/> 
<Compact @a={{hash Name='Satyam' lan='Python'}}/>

输出:

Ember.js Ember.Templates.helpers hash()方法

示例2: 输入以下代码以生成此示例的路由:

ember generate route hash2

app/components/compact2.js

{{#each-in @a as |key value|}} 
    <h3> 
        {{key}} : {{value}} 
    </h3> 
{{/each-in}}

app/templates/hash2.hbs

<h1> 
    Details are: 
</h1> 
<Compact2 @a={{hash Name='Same' Age=29}}/> 
<Compact2 @a={{hash Name='Balit' Age=25}}/>

输出:

Ember.js Ember.Templates.helpers hash()方法

参考: https://api.emberjs.com/ember/4.4/classes/Ember.Templates.helpers/methods/action?anchor=hash

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程