gpt4 book ai didi

ember.js - 你如何处理 Ember 中的多元化?

转载 作者:行者123 更新时间:2023-12-04 01:19:29 26 4
gpt4 key购买 nike

是否有任何帮助模板知道何时使用复数词?

在下面的示例中,如何使模板输出“2 狗有...”?

编码:

Ember.View.create({dog_count: 2})

模板:
{{dog_count}} (dog has)/(dogs have) gone for a walk.

最佳答案

我知道这很旧,但我今天需要它,所以就这样吧。

Ember.Handlebars.registerBoundHelper('pluralize', function(number, opts) {
var single = opts.hash['s'];
Ember.assert('pluralize requires a singular string (s)', single);
var plural = opts.hash['p'] || single + 's';
return (number == 1) ? single : plural;
});

用法:
{{questions.length}} {{pluralize questions.length s="Question"}}

或者
{{dog_count}} {{pluralize dog_count s="dog has" p="dogs have"}} gone for a walk.

复数 (p=) 选项仅在您不想要标准的 +s 行为时才需要。

关于ember.js - 你如何处理 Ember 中的多元化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10808139/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com