无法在NativeScript RadDataForm中设置未定义的属性'loadSuggestionsAsync'

时间:2019-05-23 06:48:40

标签: angular nativescript angular2-nativescript

我正在尝试从远程服务器获取autocompleteRadDataForm的数据。我得到

  

“ 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。

0 个答案:

没有答案