1

コンボドロップダウンボックスにこれを表示するために、すべての方法を試しました。「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);
?>  
4

2 に答える 2

0

This is what I get from FireBug when I type the word "Appl" into the combo box. I know the data coming back is different from what I'm typing but, I still don't get anything even when I enter something which should match.

Under the 'Params' tab I see:

_dc 1361011625341
callback    Ext.data.JsonP.callback1
limit   10
page    1
query   appl
start   0

The 'Response' tab shows:

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

The 'JSON' tab shows:

Sort by key

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"    
}
于 2013-02-16T10:36:21.827 に答える
0

jsonp プロキシを使用しています。これは、ストアをロードするデフォルトの ajax の方法ではありません。php スクリプトは、php スクリプトに送信された「callback」パラメーターから関数名を受け取る必要があり、返されるデータは次のような形式である必要があります。

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

また、'callback' を、コールバック パラメータで送信される文字列の名前に置き換えることを忘れないでください。

于 2013-02-11T19:02:20.280 に答える