2014-02-21 39 views
0

我使用預輸入自舉3,其工作的罰款。我唯一的問題是,我不能輸出get_stylesheet_directory_uri()在遠程我的JSON國家數據的URL沒有手動硬編碼整個網址。 注意:我正在使用twitter的最新typeahead.js版本。 這裏是我的代碼:如何輸出WordPress的樣式表的URI預輸入JS

var countries = new Bloodhound({ 
datumTokenizer: function(d) { return Bloodhound.tokenizers.whitespace(d.name); }, 
queryTokenizer: Bloodhound.tokenizers.whitespace, 
    limit: 10, 
    prefetch: { 
    url: ' http://Mydomainname.fr/wp-content/themes/inkness-child/lib/data/countries.json', 
filter: function(list) { 
    return $.map(list, function(country) { return { name: country }; }); 
    } 
    } 
}); 

countries.initialize(); 

$('.example-countries .typeahead').typeahead(null, { 
name: 'countries', 
displayKey: 'name', 
source: countries.ttAdapter() 
}); 

我GOOGLE了一點,發現這個:

var templateUrl = '<?php get_stylesheet_directory_uri(); ?>'; 

,我試圖implent像這樣,但未能

url: +templateUrl+/lib/data/countries.json, 

請幫助..謝謝你

回答

0

輸出與echo的網址:

<?php echo get_stylesheet_directory_uri(); ?> 

例如:

url: '<?php echo get_stylesheet_directory_uri(); ?>/lib/data/countries.json', 

documentation

+0

感謝您的快速幫助。我已經試過,但不乏與你所說的試了一次。自動填充功能無法正常工作。我一定要確定您的建議是否迴應了正確的路徑和正確的路徑。我試圖硬編碼的URL路徑,並再次工作。在我看來,js does'nt interpt php標籤。任何想法? – fritids