我正在尝试从远程服务器获取autocomplete
中RadDataForm
的数据。我得到
“ loadSuggestionsAsync”(未定义)。
同一示例在RadAutoCompleteTextView
中使用RadDataForm
可以正常工作,但是在RadDataFrom
内部是必需的。
<RadDataForm #dataform tkExampleTitle tkToggleNavButton [source]="person">
<TKEntityProperty #autocomplete tkDataFormProperty name="name" displayName="Name:" index="0" autoCompleteDisplayMode="Plain" [valuesProvider]="fromProviders">
<TKPropertyEditor tkEntityPropertyEditor type="AutoCompleteInline"></TKPropertyEditor>
</TKEntityProperty>
</RadDataForm>
@ViewChild("dataform") dataformComponent: RadDataFormComponent;
@ViewChild("autocomplete") autocomplete: RadAutoCompleteTextViewComponent;
ngOnInit(): void {
this._person = new Person("John", 23, "john@company.com", "New York", "5th Avenue", 11);
this.jsonUrl = 'myUrl';
let that = this;
let options = this.createRequestHeader();
this.autocomplete.autoCompleteTextView.loadSuggestionsAsync = function (text) {
console.error(text);
const promise = new Promise(function (resolve, reject) {
http.request({
url: that.jsonUrl + '/' + text,
method: "GET",
headers: options,
}).then(function (r: any) {
let d = r.content.toJSON();
const items: Array<TokenModel> = new Array();
for (let i = 0; i < d.length; i++) {
items.push(new TokenModel(d[i].label, null));
}
resolve(items);
}).catch((err) => {
alert(err.message);
reject();
});
});
return promise;
};
}
private createRequestHeader() {
// set headers here e.g.
const tokenInfo = appSettings.getString('TokenInfo');
return {
"Content-Type": "application/json",
"Authorization": `Bearer ${tokenInfo}`,
}
}
get fromProviders(): ObservableArray<TokenModel> {
return this._items;
}
此代码需要进行哪些更改?我正在使用NativeScript / Angular。