gpt4 book ai didi

extjs - 从extjs的下拉列表(组合框)中预选值?

转载 作者:行者123 更新时间:2023-12-04 18:13:10 27 4
gpt4 key购买 nike

我有一个显示项目数量的组合框。基于项目数量的选择,我正在显示项目的价格值。默认情况下,我将价格值设置为第一项值。但是,当我加载页面时,我希望我的组合框显示数量为100的第一项。

问题:应该加载数量:100而不是加载空白

所以我有一个商店定义为

Store =  new Ext.data.JsonStore({
storeId: 'Store',
root: 'storevalue',
autoLoad: false,
baseParams: { itemid: '${itemID!""}',
adjustPrice: '${adjustPrice}',
overrideShowPrice: '${overrideShowPrice}' },
url: 'ListQtyPrice.epm',
fields: [ 'qty', 'rawprice', 'displayPrice' ]
});

组合框显示数量
 <#if Select>
new DBEComboBox({
name: 'orderqty',
displayField: 'qty',
valueField: 'qty',
id: 'order-qty',
store: Store,
forceSelection: true,
mode: 'remote',
triggerAction: 'all',
allowBlank: true,
listWidth: 202,
triggerClass: 'orderqty-trigger',
width: 200
,defaultValue: 100
,listeners: {
// for price adjustments
}
});
</#if>


Store.load({
callback: function() {
alert("reached");
Ext.getCmp('order-qty').setValue(Store.getAt(0).get('qty'));
var oqc = Ext.getCmp('order-qty');
var value = Ext.getCmp('order-qty').getValue();
alert(" hey :" +value);
}
});

能够看到嘿:警报语句中为100

最佳答案

我已经遇到过几次这个问题。我真正解决这个问题的唯一方法是在商店加载后在组合框上调用setValue,您可以只在商店上添加一个监听器,但这对我来说总是有些困惑。我通常有一个独立的事件监听器,如下所示:

Store.on('load',function(store) {
Ext.getCmp('order-qty').setValue(store.getAt('0').get('qty'));
});

编辑: 2012年1月18日

如此处所述,确定是ComboBox的完整工作示例,其中设置了默认值。这是使用ExtJS 4.02完成的,尽管在4.07上也可以正常工作,但不确定4.1。

确保在链接中放入正确的extjs路径(请参见html顶部的括号),否则只需将combo-example和data.json放在同一目录级别,它们应该运行良好:

data.json:
[
{"value":1,"name":"Option 1"},
{"value":2,"name":"Option 2"},
{"value":3,"name":"Option 3"}
]

combo-example.html:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Combo Box Example</title>
<link rel="stylesheet" type="text/css" href="[your extjs path]/resources/css/ext-all.css">

<script type="text/javascript" src="[your extjs path]/ext-all.js"></script>
<script type="text/javascript" >

Ext.onReady(function() {

// the datastore
var myStore = new Ext.data.Store({
fields: ['value', 'name'],
proxy: {
type: 'ajax',
url : 'data.json',
reader: {
type: 'json'
}
},
autoLoad: true
});

// a window to hold the combobox inside of a form
myWindow = Ext.create('Ext.Window', {
title: 'A Simple Window',
width: 300,
constrain: true,
modal: true,
layout: 'fit',
items: [{
// the form to hold the combobox
xtype: 'form',
border: false,
fieldDefaults: {
labelWidth: 75
},
bodyPadding: '15 10 10 10',
items: [{
// the combobox
xtype: 'combo',
id: 'myCombo',
fieldLabel: 'A Label',
valueField: 'value',
displayField: 'name',
store: myStore,
//queryMode: 'local',
typeAhead: true,
forceSelection: true,
allowBlank: false,
anchor: '100%'
},{
// shows the selected value when pressed
xtype: 'button',
margin: '10 0 0 100',
text: 'OK',
handler: function() {
alert('Name: ' + Ext.getCmp('myCombo').getRawValue() +
'\nValue: ' + Ext.getCmp('myCombo').value);
}
}]
}]
});
// show the window
myWindow.show();

// function to give the combobox a default value
myStore.on('load',function(store) {
Ext.getCmp('myCombo').setValue(store.getAt('0').get('value'));
});

});

</script>

</head>
<body>
</body>
</html>

关于extjs - 从extjs的下拉列表(组合框)中预选值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8885445/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com