请帮我解决这个问题!! ..根据文本框中输入的值提供使用twitter bootstrap typeahead的自动建议。根据从bootstrap中显示的建议中选择的项目,标签动态显示文本框下方的地址和电话号码(已在数组中)根据company_id加载下拉列表。
主要的是我是一个获取数组关联id和值的结构
我的HTML是
<input class=" half" type="text" name="company_name" id="company_name" size="30" />
jscript是
$('#company_name').typeahead({
source: function(typeahead, query) {
$.ajax({
url: 'includes/get_company_details.php',
type: 'GET',
datatype: 'JSON',
async: false,
data: 'q=' + query,
success: function(result) {
console.log(result);
var convert = JSON.parse(result);
typeahead.process(convert);
}
});
}
});
我的php文件
while($row = mysql_fetch_array( $rsd )) {
$arr[] =array(
'company_name' => $row[1],
'company_id' => $row[0],
'company_reg_addr_line1' => $row[2],
'company_reg_addr_line2' => $row[3],
'company_reg_city' => $row[4],
'company_reg_city_id' => $row[10],
'company_reg_pincode' => $row[5],
'company_billing_addr_line1' => $row[6],
'company_billing_addr_line2' => $row[7],
'company_billing_city' => $row[8],
'company_billing_city_id' => $row[11],
'company_billing_pincode' => $row[9],
'company_phone_number' => $row[12]
);
}
$convert_name = json_encode($arr);
echo $convert_name;
我得到的阵列是
[
{
"company_name": "vinod company ",
"company_id": "2",
"company_reg_addr_line1": "first line",
"company_reg_addr_line2": "second line",
"company_reg_city": "66",
"company_reg_city_id": "www.vinodproduction.com",
"company_reg_pincode": "122122",
"company_billing_addr_line1": "third line",
"company_billing_addr_line2": "fourth line",
"company_billing_city": "67",
"company_billing_city_id": "909099009",
"company_billing_pincode": "121212",
"company_phone_number": "1"
},
{
"company_name": "Vignesh",
"company_id": "4",
"company_reg_addr_line1": "iji",
"company_reg_addr_line2": "ij",
"company_reg_city": "83",
"company_reg_city_id": "j",
"company_reg_pincode": "0",
"company_billing_addr_line1": "ji",
"company_billing_addr_line2": "j",
"company_billing_city": "83",
"company_billing_city_id": "hjh",
"company_billing_pincode": "0",
"company_phone_number": "1"
}
]
iF我像[&#34; kumar productions&#34;,&#34; vinod company&#34;,&#34; vignesh商人&#34;]先行者工作正常 但是我需要通过数组本身发送地址!!!
所以我改变了我在下面提到的数组。前面的类型本身不起作用。
[{"company_name":"vinod company ","company_id":"2","company_reg_addr_line1":"first line","company_reg_addr_line2":"second line","company_reg_city":"66","company_reg_city_id":"www.vinodproduction.com","company_reg_pincode":"122122","company_billing_addr_line1":"third line","company_billing_addr_line2":"fourth line","company_billing_city":"67","company_billing_city_id":"909099009","company_billing_pincode":"121212","company_phone_number":"1"},{"company_name":"Vignesh","company_id":"4","company_reg_addr_line1":"iji","company_reg_addr_line2":"ij","company_reg_city":"83","company_reg_city_id":"j","company_reg_pincode":"0","company_billing_addr_line1":"ji","company_billing_addr_line2":"j","company_billing_city":"83","company_billing_city_id":"hjh","company_billing_pincode":"0","company_phone_number":"1"}]
答案 0 :(得分:2)
您可以尝试这样的预先输出数组:
来源:
[
{ ID: 1, Name: 'Toronto' }, { ID: 2, Name: 'Montreal' },
{ ID: 3, Name: 'New York' }, {ID: 4,Name: 'Buffalo' },
{ ID: 5, Name: 'Boston' }, { ID: 6, Name: 'Columbus' },
{ ID: 7, Name: 'Dallas' }, { ID: 8, Name: 'Vancouver'},
{ ID:9, Name: 'Seattle' },{ID: 10, Name:'Los Angeles' }
]
display:'Name', val:'ID'
选择特定公司后,您可以从文本框中获取相应的公司ID,并使用所选公司ID获取公司详细信息的逻辑。