2016-08-24 162 views
0

我是SAPUI5的新手,我嘗試通過我的控制器將值設置爲視圖中的標籤。SAPUI5 this.getView(...)。byId(...)。setValue不是函數

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秒更新一次數值。

爲什麼這會拋出我這個錯誤?

回答

1

標籤沒有Value屬性,所以不存在的setValue功能(這是在錯誤的文字報道),但它有「文本」屬性,所以你應該做的:

this.getView(...).byId(...).setText(...) 
+0

噢,我的,怎麼我很傻!非常感謝。另外,還有最後一個問題。我編輯了我的問題,並添加了一個更多的錯誤,請您也看看這個問題? –

+1

在這裏看到一個很好的例子:http://stackoverflow.com/questions/3138756/calling-a-function-every-60-seconds – slkorolev