我想傳遞一個參數的功能,但得到錯誤傳遞函數參數不起作用?
無法讀取的未定義的屬性?」
var getNow= function(combo)
{
var checkValue= Ext.ComponentQuery.query('combobox[name=combo]')[0];
checkValue.isVisible();
};
//call it using this:
getNow("comboBoxName");
我想傳遞一個參數的功能,但得到錯誤傳遞函數參數不起作用?
無法讀取的未定義的屬性?」
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的字符串不會爲你解析值,所以組合是閒置在這裏。
也不起作用。你將如何使用Es6? – TheNewGuyOnTheRock
創建一個代碼片段來看看它的工作原理,你只是輸入'「comboBoxName」'到你的函數? Es6,你可以像'var a = 5; var str = \'這是$ {a}。 \'; ' – fuyushimoya
comboBoxName是我的組合框的「名稱」。但是,上面的工作。謝謝 – TheNewGuyOnTheRock
你在哪裏使用組合? – fuyushimoya
combo用於當我打電話給getNow(「comboBoxName」) – TheNewGuyOnTheRock
也許你可以在jsfiddle上創建一些示例代碼? – fuyushimoya