我在extjs中尝试新的东西,我想根据从数据库发送的值选择xtype。这个值是布尔值。所以,当它是假的,我希望那个xtype被隐藏,当它是真实的按钮。
就像这样:
if (valuefield == false){
xtype: 'hidden'
}
else{
xtype: 'button'
}我知道value字段包含false或true,但是如果其他值被添加,则会弹出错误,如何使其与if or语句一起工作?
这是我的密码:
文字:“管理员”,
xtype: 'button',
href: 'admin',
hrefTarget: '_self',
queryMode : 'local',
valueField: 'admin',
store: Ext.create('Ext.data.Store',
{
fields: ['admin'],
autoLoad: true,
proxy:
{
type: 'ajax',
url: 'admin/premision',
reader:
{
type: 'json',
root: 'data'
}
}发布于 2015-04-20 11:20:35
在以下情况下,您应该能够使用内联:
xtype: valueField ? 'button' : 'hidden'虽然设置隐藏属性可能更可取:
xtype: 'button',
hidden: valueField ? false : true发布于 2015-04-20 20:01:33
希望这把小提琴能给你一些想法-- https://fiddle.sencha.com/#fiddle/lho
Ext.application({
name : 'Test Dynamic Xtype',
launch : function() {
Ext.define('HiddenModel',{
extend: 'Ext.data.Model',
fields: [
'hidden', Boolean
]
});
// create the Data Store - This is a memory store
var store = Ext.create('Ext.data.Store', {
model: 'HiddenModel',
//autoLoad: true,
data:[{'hidden': false}]
});
// function that returns the xtype as string based on hidden: true| false
var type = function getType(hidden){
if(hidden)
return 'textarea'
else
return 'textfield'
}
Ext.create('Ext.form.FormPanel', {
title : 'Test Item Click',
width : 400,
bodyPadding: 10,
renderTo : Ext.getBody(),
items: [{
xtype: type(store.getData().items[0].data.hidden), //
text: 'My Field',
name: 'My Field',
value:'Hello'
}]
});
}
});https://stackoverflow.com/questions/29746067
复制相似问题