我对此很陌生,两周以来一直在尝试解决我的问题,现在希望您能提供帮助。
我的 JSON 输出似乎无效,但我不确定我的问题是来自 PHP 还是 extjs 脚本。
我有一个组合框,当我单击它时,它应该显示一个选项列表。该列表基本上来自 Sql 表。
当我在 Chrome 中检查控制台时,我看到了我的输出,看起来不错。
ext-all-rtl-debug.js?_dc=1525825768241:10025 [E] Ext.JSON.decode(): You're trying to decode an invalid JSON String: Connection to DB succeed
[{"id":"3","businessunit":"kappa"}]
我应该看到 kappa 并能够选择它,但我什么也没有,只有 JSON 错误。
这是我的 PHP:
<?php
require_once"..//..//_includes/headers.php";
$query = "select id, businessunit from Team_tab order by businessunit";
logit($query);
$result = odbc_exec($connection,$query);
while($row = odbc_fetch_array($result))
{
$myArray[] = array(
'id'=>$row['id'],
'businessunit'=>$row['businessunit'],
);
}
if (isset($myArray))
{
if ( sizeof($myArray) > 0 )
{
$output = json_encode($myArray);
echo $output;
}
else
{
echo '(success:true,"error":0)';
}
}
else
{
echo '(success:true,"error":0)';
}
?>
这是我的 extjs:
Ext.define('EmpMen.view.Employee.CreateEmployee', {
extend: 'Ext.window.Window',
alias: 'widget.employee.createemployee',
requires: [
'EmpMen.view.Employee.CreateEmployeeViewModel',
'EmpMen.view.Employee.CreateEmployeeViewController',
'Ext.form.Panel',
'Ext.form.field.ComboBox',
'Ext.button.Button'
],
controller: 'employee.createemployee',
viewModel: {
type: 'employee.createemployee'
},
reference: '',
height: 325,
itemId: 'createEmployee',
width: 364,
title: 'Enter Employee Information',
layout: {
type: 'vbox',
align: 'stretch'
},
items: [
{
xtype: 'form',
flex: 1,
height: 170,
padding: 10,
width: 360,
bodyPadding: 10,
title: '',
items: [
{
xtype: 'textfield',
anchor: '100%',
reference: 'first',
itemId: 'first',
fieldLabel: 'First Name'
},
{
xtype: 'textfield',
anchor: '100%',
reference: 'last',
itemId: 'last',
fieldLabel: 'Last Name'
},
{
xtype: 'textfield',
anchor: '100%',
reference: 'tle',
itemId: 'tle',
fieldLabel: 'Title'
},
{
xtype: 'combobox',
anchor: '100%',
reference: 'bunit',
fieldLabel: 'Business Unit',
displayField: 'businessunit',
valueField: 'id',
bind: {
store: '{businessunit}'
}
},
{
xtype: 'textfield',
anchor: '100%',
reference: 'exp',
itemId: 'exp',
fieldLabel: 'Experience'
},
{
xtype: 'container',
margin: 10,
layout: {
type: 'hbox',
align: 'stretch',
pack: 'center'
},
items: [
{
xtype: 'button',
flex: 1,
reference: 'employeeForm',
maxWidth: 100,
width: '',
text: 'Save',
listeners: {
click: 'onButtonClick'
}
}
]
}
]
}
],
listeners: {
afterrender: 'onCreateEmployeeAfterRender'
}
});