nativescript - Need help changing Text of label in TS Code
问题描述
On my html I have a label that shows a number of amount of images I have submitted to the server for the specific instance. My problem now is that when I upload images it does not refresh the image count, I have to close the Mobile application and open in up again to see image counter going up/.
I have tried to change the variable in the Typescript code after the images are uploaded successfully but the String does not change
<StackLayout class="m-10">
<Label [text]="imagesCount + ' Photos Uploaded'" verticalAlignment="center" class="lbl-info" horizontalAlignment="center" textWrap="true"></Label>
</StackLayout>
get imagesCount() {
this._imagesCount = workAttachments.length;
return this._imagesCount;
}
I expect the Image Label to go from 0 Photos Uploaded
to 1 Photos Uploaded
-- Edit --
This is how I upload my images
doFileUpload(file: any) {
let actualFile = fs.File.fromPath(file);
let base64 = android.util.Base64.encodeToString(actualFile.readSync(), android.util.Base64.NO_WRAP);
let workOrderAttachment = new WorkOrderAttachment(new Attachment(base64, file.replace(/^.*[\/]/, ''), 0), WorkOrderAttachmentType.PHOTO, '');
this._service.workOrderAttachment(this.job.id, workOrderAttachment, ['id']).subscribe(result => {
if (result == null) {
UserInterfaceUtil.showError("Error Uploading images.", "");
} else {
UserInterfaceUtil.showInfo("Photos uploaded successfully.", "");
this._imagesCount += 1;
}
}, error => {
UserInterfaceUtil.handleError(error);
console.log(error);
});
}
解决方案
我可以正确完成此操作的唯一方法是在表单上添加一个按钮以刷新标签。这不是做我需要做的最好的方式,但它已经完成了。
推荐阅读
- css - React Native 按钮点击区域/区域
- mongodb - 在聚合框架中多次分组,保持多个字段
- android - 在 kotlin 中使用另一个集合转换项目集合
- tfs - Azure Pipeline 中的 SSL_ERROR_SYSCALL 以访问我们的内部 TFS 2018 服务器
- typescript - Typescript 函数,它采用具有 Date 属性的对象并集,并返回将 Dates 转换为字符串的相同对象
- uml - Astah UML 是否可以生成嵌套类图?
- spring - 使用 spring cassandra 时面临的问题 - UDT 类型,无法将 udt 类型映射到 udtvalue
- java - java.lang.ExceptionInInitializerError 通过TestNG selenium 自动化打开另一个页面
- django - Django:避免从管理面板重复上传图片
- javascript - 在 node.js 中,为什么第二次调用函数所需的时间比第一次少得多?