如何在车把模板中访问功能
How to access function in Handlebars template?
如何在车把模板中获取getSum()
的值?
当我调用{{App.Address.getsum}}
时,它将返回字符串。 它包括所有功能部分。如何获得正确的值?
我试图获得getsum的价值。
App.Address = {
details: [
{
"time": "11.56",
"size": 10540,
"price": "789.5",
"direction": "Down",
"side": "Sell",
"change": "9.5",
"check": "true"
},
{
"time": "14.56",
"size": 145500,
"price": "555.5",
"direction": "Up",
"side": "Buy",
"change": "5.5"
}, {
"time": "15.56",
"size": 15550,
"price": "456",
"direction": "Down",
"side": "Sell",
"change": "9.5",
"check": "true"
}, {
"time": "11.45",
"size": 14550,
"price": "23.5",
"direction": "Down",
"side": "Buy",
"change": "5.5"
}, {
"time": "11.22",
"size": 54500,
"price": "2.5",
"direction": "Down",
"side": "Sell",
"change": "6.8",
"check": "true"
}, {
"time": "20.56",
"size": 110550,
"price": "11.8",
"direction": "Down",
"side": "Buy",
"change": "3.5"
}, {
"time": "11.13",
"size": 14343432,
"price": "88.8",
"direction": "Down",
"side": "Buy",
"change": "2.5"
},
{
"time": "13.56",
"size": 23423434,
"price": "855.8",
"direction": "Up",
"side": "Sell",
"change": "1.8",
"check": "true"
}, {
"time": "11.33",
"size": 233,
"price": "86.5",
"direction": "Up",
"side": "Buy",
"change": "6.8"
}, {
"time": "11.56",
"size": 153243,
"price": "28.5",
"direction": "Up",
"side": "Buy",
"change": "5.8"
}, {
"time": "11.15",
"size": 1344,
"price": "456",
"direction": "Down",
"side": "Buy",
"change": "1.1"
}
],
getSum: function() {
var details = this.details;
var sum = 0;
for (var i = 0, length = details.length; i < length; i++) {
sum += parseInt(details[i].size, 10);
}
return sum;
}
}
将函数创建为属性。
getSum: function() {
var details = this.details;
var sum = 0;
for (var i = 0, length = details.length; i < length; i++) {
sum += parseInt(details[i].size, 10);
}
return sum;
}.property()
然后,您可以通过模板中的 {{App.Address.getSum}} 调用它。
相关文章:
- javascript函数访问ios本机功能
- 为什么可以't我访问Chrome内置功能$
- 可以't访问Angular.js服务中的功能
- 访问内部功能范围的元素,而不是敲除中的外部
- 在接受功能上访问燃料UX标语牌中的“this”
- 控制器切换后匿名功能中的访问服务数据发生变化
- 使用Flash CC和Createjs的子访问功能
- 通过访问DOM添加功能
- 模态无法访问其显示功能
- JqueryUI访问修改拖拽功能
- 当某些用户已经访问某个页面时,阻止访问或禁用该页面中的某些功能
- 访问谷歌地图事件中的Backbone.View功能
- 如何在车把模板中访问功能
- 如何在右键单击链接并从上下文菜单访问功能后获取链接的 DOM
- 访问功能内的成员/从外部设置成员
- 咖啡脚本访问功能
- 如何通过按钮从express.js访问功能到客户端
- 不一致的“与”行为-没有访问功能-这是一个chrome的错误
- 在动态添加的javascript文件中提供访问功能
- 如何访问功能