0
私はajaxを介して要求するcompanyinfo.jsというファイルに格納された配列内のすべての項目を反映するためのドロップダウン・オプションを必要とします。ページが読み込まれたらdropDownList()
と呼んでいます。javascriptのブートストラップ・タイプヘッドのデータ・ソースを更新する
function dropDownList (evt) {
console.log("dropdownfired");
var companyArray = [];
$.ajax({
url : 'assets/data/companyarray.js', //this file is just ["Facbeook", "Twitter", "Klout",]
dataType: 'script',
success: function(data) {
companyArray = data;
console.log(companyArray); //returns an array of the companies
$('#companyInput1').attr('data-source', companyArray); //#companyInput1 is the input field where I want the typehead to be
console.log($('#companyInput1').attr('data-source')); //returns undefined
}
});
}
UPDATES:
function dropDownList (evt) {
console.log("dropdownfired");
var companyArray = [];
$.ajax({
url : 'assets/data/companyarray.js', //this file is just ["Facbeook", "Twitter", "Klout",]
dataType: 'script',
success: function(data) {
companyArray = data;
console.log(companyArray); // gives array of companies
$('#companyInput1').data('data-source', companyArray);
console.log($('#companyInput1').data('data-source')); // gives undefined still
}
});
}
何らかの理由でまだ動作していません。上の私の更新されたコードをチェックアウト –