Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ember.js 在bindAttr中应用函数_Ember.js - Fatal编程技术网

Ember.js 在bindAttr中应用函数

Ember.js 在bindAttr中应用函数,ember.js,Ember.js,我需要对属性值应用一个函数。我使用以下代码将其与inputbox绑定 {{bindAttr value="ticket.t_date"}} 我有一个助手函数,如下所示 Ember.Handlebars.helper('date', function(unixDate){ return unixToDate(unixDate); }); 我需要在bindAttr内使用此函数。在bind attr内调用帮助程序是不可能的,但您可以通过另一种方式来实现,在模型类上定义一个计算属性,将日期格式帮助程

我需要对属性值应用一个函数。我使用以下代码将其与inputbox绑定

{{bindAttr value="ticket.t_date"}}
我有一个助手函数,如下所示

Ember.Handlebars.helper('date', function(unixDate){ return unixToDate(unixDate); });

我需要在bindAttr内使用此函数。

在bind attr内调用帮助程序是不可能的,但您可以通过另一种方式来实现,在模型类上定义一个计算属性,将日期格式帮助程序函数用作普通函数调用:

App.Ticket = DS.Model.extend({
  t_date: DS.attr('string'),
  formattedDate: function () {
    return unixToDate(this.get('t_date'));
  }.property('t_date')
});
然后在
绑定属性中使用
格式化日期

{{#each ticket in model}}
  <input type="text" {{bindAttr value="ticket.formattedDate"}}></input>
{{/each}}

希望有帮助。

bind attr
中调用帮助程序是不可能的,但您可以通过另一种方式来实现,即在模型类上定义一个计算属性,将日期格式帮助程序函数用作普通函数调用:

App.Ticket = DS.Model.extend({
  t_date: DS.attr('string'),
  formattedDate: function () {
    return unixToDate(this.get('t_date'));
  }.property('t_date')
});
然后在
绑定属性中使用
格式化日期

{{#each ticket in model}}
  <input type="text" {{bindAttr value="ticket.formattedDate"}}></input>
{{/each}}

希望有帮助。

问题是我在控制器的属性中设置了json。像controller.set('ticket',json);是否仍然可以像您所展示的那样在我的票据中使用计算属性。问题是我在控制器中的属性中设置了json。像controller.set('ticket',json);是否有可能像你所展示的那样,在我的票据中仍然使用计算属性。