来自本地阵列的ExtJs Combobox

Pre*_*One 6 html javascript combobox extjs arraylist

我试图使用本地数组列表填充Ext Js组合框.在Ext Js示例中,组件是从不同的states.js文件填充的.

在我的例子中,数据应该来自局部变量.它不起作用.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Combo Boxes</title>
<link rel="stylesheet" type="text/css" href="../../resources/css/ext-all.css" />
<script type="text/javascript" src="../../adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="../../ext-all.js">
</head>

<body>
<script type="text/javascript">
var  exampleData2 = [['1', 'hello'],['2', 'hi'],['3', 'bye']];
Ext.onReady(function(){
Ext.QuickTips.init();

// simple array store
var store = new Ext.data.ArrayStore({
    fields: ['abbr', 'state'],
    data : exampleData2 
});
  var combo = new Ext.form.ComboBox({
    store: store,
    displayField:'state',
    typeAhead: true,
    mode: 'local',
    forceSelection: true,
    triggerAction: 'all',
    emptyText:'Select a state...',
    selectOnFocus:true,
    applyTo: 'local-states'
    });
  </script>

<div>
<input type="text" id="local-states" size="20"/>
</div>
<div id="local-states" style="margin-top:10px">

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

ben*_*siu 7

范围,范围,范围

Ext.onReady(function(){ 
  Ext.QuickTips.init();  // simple array store 
  var exampleData2 = [['1', 'hello'],['2', 'hi'],['3', 'bye']];
  var store = new Ext.data.ArrayStore({
     fields: ['abbr', 'state'],
     data : exampleData2 
     // or even better data : [['1', 'hello'],['2', 'hi'],['3', 'bye']]
     // next to change: combo.getStore().loadData( new_table );
  });
  var combo = new Ext.form.ComboBox({
     store: store,
     displayField:'state',
     typeAhead: true,
     mode: 'local',
     forceSelection: true,
     triggerAction: 'all',
     emptyText:'Select a state...',
     selectOnFocus:true,
     applyTo: 'local-states'
   });
});

获得更复杂的解决方案

Ext.ux.states = Ext.Extend ( Ex.form.ComboBox, { ....