2016-05-30 154 views
0

我有一個表單讓我們讓用戶使用geonames API和kendoComboBox選擇一個位置。但是,如果用戶選擇(單擊)列表中的第一個項目,這實際上不會選擇該項目。只有當他們選擇任何其他項目,然後再次選擇第一個項目實際上工作。
選擇任何其他項目,但第一個工作正常。選擇kendoComboBox中的第一個項目

任何人都可以指出爲什麼這可能是這種情況,我該如何解決它?
這裏是我的代碼:

<tr> 
    <td><label>Location:</label></td> 
    <td><input id="toBeSetByJS" class="locationDisplay" readonly></td> 
    <td><label>Select Location:</label></td> 
    <td><input class="locationSelector" id="toBeSetByJS2" type="text">{{ form.location }}</td> 
</tr> 

<script>    
$(".locationSelector").each(function(index) { 

// name of hidden input element 
var locationInput = $(this).next("input").attr("id"); 

// set names of selector and display 
var locationDisplay = locationInput + "-display"; 
$(this).parent().prev().prev().children().attr("id", locationDisplay);         

var locationSelector = locationInput + "-selector"; 
$(this).attr("id", locationSelector);  

// initialize the location display if necessary 
var locationid = $("#" + locationInput).val(); 

if (locationid != "") { 
    getLocationName(locationid, locationDisplay); 
}  

var isocode = $("#isocode").val();  

$(this).kendoComboBox({ 
    placeholder: "Select location...", 
    dataTextField: "name", 
    dataValueField: "geonameId", 
    template: '<b>${ data.name }</b>, ${ data.adminName1 }, ${ data.countryName } (${data.fcode})', 
    filter: "startswith", 
    dataSource: { 
     serverFiltering: true, 
     transport: { 
      read: { 
       url: "http://api.geonames.org/searchJSON", 
       dataType: "jsonp", 
       data: { 
        featureClass: "P", 
        style: "full", 
        maxRows: 12, 
        countryBias: isocode, 
        username: "my.username", 
        name_startsWith: function() { 
         return $("#" + locationSelector).data("kendoComboBox").text();       
        } 
       } 
      } 
     }, 
     schema: { 
      data: "geonames" 
     } 
    }, 
    change: function() { 
     $("#" + locationDisplay).val(this.text()); 
     $("#" + locationInput).val(this.value()); 

    } 
}); 
}); 


function getLocationName(geoid, locationDisplayField) { 

$.ajax({ 
    url: "http://api.geonames.org/getJSON", 
    dataType: 'jsonp', 
    data: { 
     geonameId: geoid, 
     style: "full", 
     username: "my.username" 
    }, 
    success: function(data) { 
     //var locName = (data.name + ", " + data.adminName1 + ", " + data.countryName); 
     $("#" + locationDisplayField).val(data.name); 

    }, 
    error: function (xhr, textStatus) { 
     alert('Ooops, geonames server returned: ' + textStatus); 
    } 
}); 


} 

</script> 
+0

你可以使[此演示](http://dojo.telerik.com/iQuyo)工作,使這更容易幫助你..? – DontVoteMeDown

回答

0

要設置使用JQuery劍道組合框的默認值,你可以不喜歡這個 -

var combobox = $("#combobox").data("kendoComboBox"); 
combobox.value("Europe"); 

看看這會有所幫助。

相關問題