无法预填充 kendo-inputfield

can't prefill a kendo-inputfield

我无法预填其中一个输入字段,我也不知道为什么。 (顺便说一句,我在这个项目中使用 kendo / angular js)。这是我的输入框

<input id="selection" class="form-element-small" kendo-auto-complete
k-data-text-field="'city_name'" ng-model="autocomplete" k-data-source="cities"
 k-placeholder="'Enter a city'"/>

这是失败的脚本代码:

var city_name_pre = window.localStorage.getItem('city_name');
if (city_name_pre != null) {
    console.log(city_name_pre);
    console.log($('#selection').val());
    $('#selection').val(city_name_pre);
    console.log($('#selection').val());
}

首先 console.log 说 "boston"。第二个 console.log 说“”(好吧.. 当然 ;))。第三个 console.log 说 "boston" 就像它应该的那样。

但实际输入字段仍然是空的,浏览器中的检查器也显示 value=""。

如果您将值推送到 ng 模型,没有帮助吗?

var city_name_pre = window.localStorage.getItem('city_name');
if (city_name_pre != null) {
    $scope.autocomplete = city_name_pre;
}