1

JSON 응답에서 반환 된 새 데이터로 win1.title (레이블)을 업데이트해야합니다. 내 콘솔 win1.title 값에 인쇄 할 수 있지만 새 값을 할당 할 수 없습니다!현재 창에서 텍스트 레이블을 업데이트하는 방법

var win1 = Titanium.UI.createWindow({ 
    title:'Tab 1', 
    backgroundColor: 'black', 
    layout: 'vertical', 
    url: 'win1.js', 
    title: 'Loading...', 
    artist: '' }); 


win1.open(); 

//Fetching data 

var jsonData = ''; var pointer = 0; 

var url = "http://example.com"; var xhr = Ti.Network.createHTTPClient({ 
    onload: function(e) { 

     jsonData = JSON.parse(this.responseText).response.songs; 



     //HERE I NEED TO UPDATE win1.title with title returned by JSON 
     /* 
      if a print win1.title it works correctly. 
      console.log(win1.title); 

      but if I try to assign data to win1.title nothing happens, even a error! 

     */ 


     win1.addEventListener('swipe', function(e) { 
         console.log("win1 title:" + win1.title);   win1.title = jsonData[pointer].title;   win1.artist = jsonData[pointer].artist_name;   win1.image = jsonData[pointer].tracks[0].release_image; 

        }); 

    }, 
    onerror: function(e) { 
     console.log(e); 
    }, 
    timeout:20000 /* in milliseconds */ }); xhr.open("GET", url); xhr.send(); // request is actually sent with this statement 

app.js win1.title = 'some title';는 당신이이 경우 것입니다 생각하지 않을 것입니다 설정

(function() { 

    var win1 = Ti.UI.currentWindow; 

    var image = Ti.UI.createImageView({ 
     image:win1.image, 
     top: 40 
    }); 

    var title = Ti.UI.createLabel({ 
     color: 'white', 
     font: { fontSize:38 }, 
     text: win1.title, 
     textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER, 
     top: 20, 
     width: 'auto', height: 'auto' 
    }); 

    var artist = Ti.UI.createLabel({ 
     color: 'white', 
     font: { fontSize:28 }, 
     text: win1.artist, 
     textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER, 
     top: 30, 
     width: 'auto', height: 'auto' 
    }); 


    win1.add(title); 
    win1.add(artist); 
    win1.add(image); 


})(); 

답변

4

을 win1.js. Titanium Window objectstitle 속성을 가지고 있으며 iOS 또는 Android 용으로 빌드하는지 여부에 따라이 제목이 모달 창 상단이나 탭 그룹 또는 탐색 그룹에 표시됩니다.

코드가이 제목을 업데이트하고 있지만 사용자가 볼 수 없습니다. (createWindow() 선언에 modal:true을 추가하십시오.) 또한 2 title 속성을 설정 했으므로 그 중 하나를 제거하십시오. 다시, 그리고

win1.updateTitle = function(newTitle){ 
    title.text = newTitle; 
} 

: 다음을 추가, win1.js에서

:

는 다음을 수행 할 수 있습니다, win1.js에 '제목'라는 이름의 변수에 레이블 텍스트를 변경하려면 app.js에, 당신은 제목을 업데이트하여 원하는 목적지로 이동하십시오 또한

win1.updateTitle('new title'); 

, 당신은 당신의 티타늄 프로젝트 CommonJS를 사용하는 것이 좋습니다 :

CommonJS Best Practices

+0

CommonJS (따라서 훌륭한 아키텍처)의 중요성을 강조하기 위해 선정되었습니다. –

관련 문제