【问题标题】:SAPUI5 this.getView(...).byId(...).setValue is not a functionSAPUI5 this.getView(...).byId(...).setValue 不是函数
【发布时间】:2016-08-24 16:01:19
【问题描述】:

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

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 都返回值,我试图将这些值设置到标签中。这是一件非常简单的事情,但我错过了一些东西,因为在我的控制台中

this.getView(...).byId(...).setValue is not a function

编辑:另外,在我的 onInit 函数中编写我的重复函数以每 1 秒运行一次,有什么特别的方法吗?因为它说重复不是一个函数。重复功能的重点是每 1 秒更新一次值。

为什么这会引发这个错误?

【问题讨论】:

    标签: sapui5


    【解决方案1】:

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

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

    【讨论】:

    • 天哪,我真傻!非常感谢。另外,最后一个问题。我已经编辑了我的问题并添加了一个我遇到的错误,您也可以看看吗?
    • 在这里查看一个很好的例子:stackoverflow.com/questions/3138756/…
    猜你喜欢
    • 1970-01-01
    • 2023-03-24
    • 2017-09-05
    • 1970-01-01
    • 2016-12-25
    • 2021-07-29
    • 2021-10-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多