SAPUI5 this.getView(...).byId(...).setValue 不是函数 [英] SAPUI5 this.getView(...).byId(...).setValue is not a function

查看:43
本文介绍了SAPUI5 this.getView(...).byId(...).setValue 不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 SAPUI5 的新手,我正在尝试通过我的控制器将值设置到我视图中的标签中.

I'm new to SAPUI5 and I'm trying to set a value into a label in my view via my controller.

View1.controller.js

onInit: function()
        {
            var currentTime = this.whatsTheTime();
            var currentDate = this.whatsTheDate();
            this.getView().byId("timeDisplay").setValue(currentTime);
            this.getView().byId("dateDisplay").setValue(currentDate);

                this.repeat(function() {
                        currentTime = this.whatsTheTime();
                        currentDate = this.whatsTheDate();
                        this.getView().byId("timeDisplay").setText(currentTime);
                        this.getView().byId("dateDisplay").setText(currentDate);
                }, 1000);

view.xml

<mvc:View controllerName="testApp.controller.View1" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m">
    <Label  id = "timeDisplay" design="Bold" />
    <Label  id = "dateDisplay" design="Bold"/>
    <Button
        text = "Click me"
        press = "doNothing"  />
</mvc:View>

基本上,在控制器中,whatsTheTime 和 whatsTheDate 都返回值,我正在尝试将这些值设置到标签中.这是一件非常简单的事情,但我错过了一些东西,因为在我的控制台中

Basically, in the controller, whatsTheTime and whatsTheDate both return values and I'm trying to set those values into the label. It's a pretty simple thing but I'm missing out something because in my console

this.getView(...).byId(...).setValue 不是函数

另外,在我的 onInit 函数中每 1 秒运行一次重复函数有什么特别的方法吗?因为它说重复不是一个函数.repeat 函数的重点是每 1 秒更新一次值.

Also, is there any particular way in writing my repeat function to run every 1 second inside my onInit function? Because it says that repeat is not a function. The whole point of the repeat function is to update the value every 1 second.

这到底是为什么让我出现这个错误?

Why exactly is this throwing me up this error?

推荐答案

Label 没有 Value 属性,所以没有 setValue 函数(错误文本中报错),但是它有 "text" 属性,所以你应该这样做:

Label does not have a Value property, so there is no setValue function (which is reported in error text), but it has "text" property, so you should do:

this.getView(...).byId(...).setText( ... )

这篇关于SAPUI5 this.getView(...).byId(...).setValue 不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆