简体   繁体   中英

Passing function parameter not working?

I want to pass a parameter to the function, but getting error

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");

Try

var checkValue= Ext.ComponentQuery.query('combobox[name=combo]')[0];

change to

var checkValue= Ext.ComponentQuery.query('combobox[name=' + combo + ']')[0];

Added snippet, it seems work, so you have to give further informations.

 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"/> 

Unless you use Es6 with special string notation, javascript's string won't parse value for you, so the combo is unused here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM