extjs-使用传递的参数创建自定义函数
ext js - create custom function with passed parameters
只是一个警告,这是我的第一个ExtJS项目。我已经成功地从Web服务器加载了两个存储。
- 包含位置的存储
- 包含市场数据的商店
我创建了第三个商店来保存我的所有结果。现在我想遍历每个仓位,找到相关的市场数据记录,并进行简单的计算。
我已经成功地完成了这一切,只需点击一个按钮,但我想把做实际计算的功能分开。。。传入参数。
现在,为了让这个概念发挥作用,我创建了一个名为"sayHello"的函数,但我收到了一个错误,说明。。。ReferenceError:sayHello未定义。
有人能指出我在创建这个自定义函数时做错了什么吗?
谢谢!
我的控制器。。。
Ext.define('ExtApplication1.view.clientdetails.clientdetailsController', {
extend: 'Ext.app.ViewController',
alias: 'controller.clientdetails-clientdetails',
onClickCalculate: function () {
console.log('calculation button was hit');
var targetGrid = Ext.getCmp('positionsGridID');
var positionsStore = targetGrid.store;
var marketDataGrid = Ext.getCmp('marketsGridID');
var marketDataStore = marketDataGrid.store;
var calculatedPositionsDataGrid = Ext.getCmp('calculatedPositionsGridID');
var calculatedPositionsDataStore = calculatedPositionsDataGrid.store;
console.log(calculatedPositionsDataStore);
positionsStore.each(function (record) {
console.log('the details for the whole position');
console.log(record);
var bbSymbol = record.get('BBSymbol');
var singleRecord;
marketDataStore.each(function (record) {
var cycleBBSymbol = record.get('BBSymbol');
if (cycleBBSymbol === bbSymbol){
singleRecord = record;
return false;
}
});
console.log('position I am evaluateing is ' + bbSymbol);
console.log('market data found for ' + singleRecord.get('BBSymbol'));
console.log(singleRecord);
//debugger;
var lastPrice = singleRecord.get('Last_Price');
var settle = singleRecord.get('Px_Settle');
var qty = record.get('Quantity');
var marketName = record.get('Description');
var pnl = (lastPrice - settle) * qty;
console.log(pnl);
calculatedPositionsDataStore.add({
BBSymbol: bbSymbol,
Description: marketName,
Quantity: qty,
CalcPLSett: pnl
});
sayHello(singleRecord);
}, this);
},
sayHello: function (singleRecord) {
alert('hello');
alert(singleRecord);
}
});
出现此错误是因为您超出了ViewController的范围。
在中
positionsStore.each(function (record) { ...}
您在存储范围内,但是sayHello函数在ViewController范围内。
将ViewController的作用域分配给一个变量,应该可以解决您的问题:
onClickCalculate: function () {
console.log('calculation button was hit');
var me = this; //NEW LINE
var targetGrid = Ext.getCmp('positionsGridID');
var positionsStore = targetGrid.store;
然后在positionsStore.each
函数中使用:
me.sayHello(singleRecord)
相关文章:
- 如何使用JQuery在HTML中创建包含字符串参数的引号的onclickjavascript链接
- 如何在HTML元素上创建函数,而不是将元素作为参数传递
- 使用参数创建对象
- 为什么在创建作用域时将参数传递给anon函数
- 根据发送到javascript中函数的参数创建变量名
- JavaScript 函数,用于使用该参数创建 URL
- extjs-使用传递的参数创建自定义函数
- 从 JavaScript 中的参数创建变量名称
- 使用变量参数创建新的 JavaScript 对象
- Javascript-使用相同的参数创建多个对象
- Symfony2使用数据库参数创建dynamc链接
- JS用self作为参数创建自定义对象
- 如何使用参数创建JQuery自定义函数
- 在JavaScript中使用my参数创建一个新的Date()
- 如何在javascript中基于参数创建对象的单例实例
- 在javascript中使用参数创建对象
- 从函数参数创建一个变量
- 使用多个参数创建检查以产生三个不同的结果
- jQuery+JavaScript:使用单个对象作为参数创建自定义ajax调用函数
- 在使用Object时传递参数.创建而不是新建