Typescript Nativescript-添加新值时,数据不会刷新/更新
我的应用程序在添加新值时不刷新/更新标签或其他输入,这是一个非常奇怪的问题,因为添加值的函数工作正常,但视图没有使用新值刷新,我只有在单击“上一步”按钮时才能看到新值。你可以在这个视频中看到这个bug。 TNS版本是3.3.1 我的代码: view.htmlTypescript Nativescript-添加新值时,数据不会刷新/更新,typescript,data-binding,nativescript,Typescript,Data Binding,Nativescript,我的应用程序在添加新值时不刷新/更新标签或其他输入,这是一个非常奇怪的问题,因为添加值的函数工作正常,但视图没有使用新值刷新,我只有在单击“上一步”按钮时才能看到新值。你可以在这个视频中看到这个bug。 TNS版本是3.3.1 我的代码: view.html <ActionBar class="action-bar" > <Label class="action-bar-title title" [text]="hostname"></Label&
<ActionBar class="action-bar" >
<Label class="action-bar-title title" [text]="hostname"></Label>
<NavigationButton text="{{ 'msg_btn_close' | translate }}" icon="res://ic_chevron_left_white_24dp" (tap)="goBack()"></NavigationButton>
</ActionBar>
<TabView #proxyTabView>
<StackLayout *tabItem="{iconSource: 'res://ic_dashboard_black_24dp'}">
<GridLayout columns="*,*,*,*" rows="auto, 180, 180">
<GridLayout colSpan="4" columns="*" row="0">
<RadDataForm tkExampleTitle tkToggleNavButton #proxyServerForm [source]="proxyData">
<TKEntityProperty tkDataFormProperty name="hostname" displayName="{{ 'msg_ip_hostname' | translate }}" index="1">
<TKPropertyEditor tkEntityPropertyEditor>
<TKPropertyEditorStyle tkPropertyEditorStyle labelHidden="false" labelTextSize="15"ios:labelFontName="Questrial" android:labelFontName="Questrial-Regular" labelPosition="Top"></TKPropertyEditorStyle>
</TKPropertyEditor>
<TKNonEmptyValidator tkEntityPropertyValidators errorMessage="{{ 'msg_error_ip_empty' | translate }}" ></TKNonEmptyValidator>
</TKEntityProperty>
</RadDataForm>
</GridLayout>
</GridLayout>
</StackLayout>
<StackLayout *tabItem="{iconSource: 'res://ic_http_black_24dp'}">
<Label text="This is Label in Tab 2"></Label>
</StackLayout>
<StackLayout *tabItem="{iconSource: 'res://ic_memory_black_24dp'}">
<Label text="This is Label in Tab 2"></Label>
</StackLayout>
<StackLayout *tabItem="{iconSource: 'res://ic_network_check_black_24dp'}">
<Label text="This is Label in Tab 2"></Label>
</StackLayout>
</TabView>
问候您在ngOnInit上使用NgZone inside修复问题
ngOnInit() {
this.hostname ="Loading data"
this.worker.onmessage = (msg) =>{
this.zone.run(() => {
if (msg.data!=="error"){
this._proxyData = new ProxyData(msg.data.os.hostname);
this.hostname=msg.data.os.hostname
console.log(msg.data.os.hostname);
}
});
}
this.worker.onerror = (e) =>{
console.log(e.message);
}
}
ngOnInit() {
this.hostname ="Loading data"
this.worker.onmessage = (msg) =>{
this.zone.run(() => {
if (msg.data!=="error"){
this._proxyData = new ProxyData(msg.data.os.hostname);
this.hostname=msg.data.os.hostname
console.log(msg.data.os.hostname);
}
});
}
this.worker.onerror = (e) =>{
console.log(e.message);
}
}