传递函数参数不起作用?
Passing function parameter not working?
我想向函数传递一个参数,但出现错误
Cannot read property of undefined?"
var getNow= function(combo)
{
var checkValue= Ext.ComponentQuery.query('combobox[name=combo]')[0];
checkValue.isVisible();
};
//call it using this:
getNow("comboBoxName");
尝试
var checkValue= Ext.ComponentQuery.query('combobox[name=combo]')[0];
改为
var checkValue= Ext.ComponentQuery.query('combobox[name=' + combo + ']')[0];
添加了代码片段,它似乎有效,因此您必须提供更多信息。
var states = Ext.create('Ext.data.Store', {
fields: ['abbr', 'name'],
data : [
{"abbr":"AL", "name":"Alabama"},
{"abbr":"AK", "name":"Alaska"},
{"abbr":"AZ", "name":"Arizona"}
]
});
Ext.create('Ext.form.ComboBox', {
fieldLabel: 'Choose State',
store: states,
queryMode: 'local',
valueField: 'abbr',
name: "asd",
renderTo: Ext.getBody(),
// Template for the dropdown menu.
// Note the use of the "x-list-plain" and "x-boundlist-item" class,
// this is required to make the items selectable.
tpl: Ext.create('Ext.XTemplate',
'<ul class="x-list-plain"><tpl for=".">',
'<li role="option" class="x-boundlist-item">{abbr} - {name}</li>',
'</tpl></ul>'
),
// template for the content inside text field
displayTpl: Ext.create('Ext.XTemplate',
'<tpl for=".">',
'{abbr} - {name}',
'</tpl>'
)
});
var getNow= function(combo)
{
var checkValue= Ext.ComponentQuery.query('combobox[name=' + combo+ ']')[0];
console.log(checkValue.isVisible()); // It returns true or false, then what you want it to do?
};
//call it using this:
getNow("asd");
<script src="https://cdnjs.cloudflare.com/ajax/libs/extjs/4.2.1/ext-all.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/extjs/4.2.1/resources/css/ext-all.css" rel="stylesheet"/>
除非你使用带有特殊字符串符号的 Es6,否则 javascript 的字符串不会为你解析值,所以这里没有使用组合。
我想向函数传递一个参数,但出现错误
Cannot read property of undefined?"
var getNow= function(combo)
{
var checkValue= Ext.ComponentQuery.query('combobox[name=combo]')[0];
checkValue.isVisible();
};
//call it using this:
getNow("comboBoxName");
尝试
var checkValue= Ext.ComponentQuery.query('combobox[name=combo]')[0];
改为
var checkValue= Ext.ComponentQuery.query('combobox[name=' + combo + ']')[0];
添加了代码片段,它似乎有效,因此您必须提供更多信息。
var states = Ext.create('Ext.data.Store', {
fields: ['abbr', 'name'],
data : [
{"abbr":"AL", "name":"Alabama"},
{"abbr":"AK", "name":"Alaska"},
{"abbr":"AZ", "name":"Arizona"}
]
});
Ext.create('Ext.form.ComboBox', {
fieldLabel: 'Choose State',
store: states,
queryMode: 'local',
valueField: 'abbr',
name: "asd",
renderTo: Ext.getBody(),
// Template for the dropdown menu.
// Note the use of the "x-list-plain" and "x-boundlist-item" class,
// this is required to make the items selectable.
tpl: Ext.create('Ext.XTemplate',
'<ul class="x-list-plain"><tpl for=".">',
'<li role="option" class="x-boundlist-item">{abbr} - {name}</li>',
'</tpl></ul>'
),
// template for the content inside text field
displayTpl: Ext.create('Ext.XTemplate',
'<tpl for=".">',
'{abbr} - {name}',
'</tpl>'
)
});
var getNow= function(combo)
{
var checkValue= Ext.ComponentQuery.query('combobox[name=' + combo+ ']')[0];
console.log(checkValue.isVisible()); // It returns true or false, then what you want it to do?
};
//call it using this:
getNow("asd");
<script src="https://cdnjs.cloudflare.com/ajax/libs/extjs/4.2.1/ext-all.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/extjs/4.2.1/resources/css/ext-all.css" rel="stylesheet"/>
除非你使用带有特殊字符串符号的 Es6,否则 javascript 的字符串不会为你解析值,所以这里没有使用组合。