Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Combobox 似乎无法在Extjs中远程填充组合框_Combobox_Extjs4.1 - Fatal编程技术网

Combobox 似乎无法在Extjs中远程填充组合框

Combobox 似乎无法在Extjs中远程填充组合框,combobox,extjs4.1,Combobox,Extjs4.1,我尝试了所有manor的方法来填充combo下拉框。 当输入时,比如说“Apple”,它似乎正在加载数据,但在下拉框中没有任何结果。Firebug显示数据已加载。那么,我错在哪里呢?谢谢 Ext.create('Ext.form.field.ComboBox', { fieldLabel: 'Basket', emptyText : 'Type a fruit name', queryMode : 'remote', minChars : 3,

我尝试了所有manor的方法来填充combo下拉框。 当输入时,比如说“Apple”,它似乎正在加载数据,但在下拉框中没有任何结果。Firebug显示数据已加载。那么,我错在哪里呢?谢谢

Ext.create('Ext.form.field.ComboBox', { 
    fieldLabel: 'Basket',
    emptyText : 'Type a fruit name',
        queryMode : 'remote',
        minChars  : 3, 
        fields    : ['id', 'name'], 
        store     : { 
                    proxy: {
                type: 'jsonp',
                callbackKey: 'method',
                url: 'http://www.comparetrainfares.co.uk/train_scripts/data.php',
                reader: {
                root: 'items'
            },
                }
             },
        needleKey     : 'query',
        labelKey      : 'id',
        label         : 'name',
        displayField  : 'name',
        width         : 260, 
        forceSelection: true,
        renderTo      : query1,
});



<?php
header('Access-Control-Allow-Origin: *');
//header('Content-Type: application/json; charset=utf8');
//header('Content-Type: application/x-json');


// http://www.comparetrainfares.co.uk/train_scripts/data.php

$output = array();

$output[] = array('id' => '1', 'name' => 'Apple');
$output[] = array('id' => '2', 'name' => 'Banana');
$output[] = array('id' => '3', 'name' => 'Orange');
$output[] = array('id' => '4', 'name' => 'Lemon');

$objects = array('items' => $output);

echo json_encode($objects);
?>  
Ext.create('Ext.form.field.ComboBox',{
fieldLabel:“篮子”,
emptyText:'键入水果名称',
queryMode:'远程',
明查斯:3,
字段:['id','name'],
存储:{
代理:{
键入:“jsonp”,
callbackKey:'方法',
网址:'http://www.comparetrainfares.co.uk/train_scripts/data.php',
读者:{
root:'项目'
},
}
},
needleKey:'查询',
labelKey:'id',
标签:“名称”,
displayField:'名称',
宽度:260,
选择:对,
renderTo:query1,
});

您正在使用jsonp代理。这不是加载存储的默认ajax方式。php脚本应该从发送到php脚本的“callback”参数中接收函数名,然后返回的数据应该采用如下格式:

callback({"items":[{"id":"1","name":"Apple"},{"id":"2","name":"Banana"},{"id":"3","name":"Orange"},{"id":"4","name":"Lemon"}]})

记住用callback参数中发送的任何字符串的名称替换“callback”。

这是我在组合框中键入单词“Appl”时从FireBug得到的结果。我知道返回的数据与我输入的数据不同,但是,即使我输入了应该匹配的内容,我仍然没有得到任何信息

在“参数”选项卡下,我看到:

_dc 1361011625341
callback    Ext.data.JsonP.callback1
limit   10
page    1
query   appl
start   0
“响应”选项卡显示:

{rows:[{"id":"1","genre_name":"Comedy"},{"id":"2","genre_name":"Drama"},{"id":"3","genre_name":"Action"},{"id":"4","genre_name":"Mystery"}]}
“JSON”选项卡显示:

{rows:[{"id":"1","genre_name":"Comedy"},{"id":"2","genre_name":"Drama"},{"id":"3","genre_name":"Action"},{"id":"4","genre_name":"Mystery"}]}
按键排序

rows    
[Object { id=    
"1"    
,  genre_name=    
"Comedy"    
}, Object { id=    
"2"    
,  genre_name=    
"Drama"    
}, Object { id=    
"3"    
,  genre_name=    
"Action"    
}, Object { id=    
"4"    
,  genre_name=    
"Mystery"    
}]    

0
    Object { id=    
"1"    
, genre_name=    
"Comedy"    
}       
1
    Object { id=    
"2"    
, genre_name=    
"Drama"    
}       
2
    Object { id=    
"3"    
, genre_name=    
"Action"    
}       
3
    Object { id=    
"4"    
, genre_name=    
"Mystery"    
}

尝试将
键入:“json',
添加到您的
阅读器
配置中。不,这不起作用-我确信我以前尝试过-谢谢。向我们展示一个php脚本生成的输出示例。如果您在浏览器中弹出此脚本,您可以查看php脚本的输出,谢谢您的反馈。你能不能给我举个例子,因为我还没有很快取得任何进展。我刚刚意识到我的答案有点错。我已经更新了它。我添加了“items”对象,因为它是由jsonp配置定义为根的。我仍然没有在下拉列表中获得任何内容。数据肯定回来了,因为我可以在FireBug中看到它!请为我粘贴您在firebug中看到的内容。