Search code examples
smartface.io

Smartface get data value with code


I want to get data value with code. I added label in RepeatBox. I can't get value. My codes as follows. Where I doing wrong?

    var deger="";
    var wc;
    


    function Page2_TextButton1_OnPressed(e){
   
       wc = new SMF.Net.WebClient({
            
            URL:"http://192.168.42.19/TestRestApi/api/Comment/Notlar",
            httpMethod:"GET",
            requestHeaders: ["content-type", "application/json"],
            onSyndicationSuccess: function(e) {
    
                deger = wc.response;
                
                Pages.Page2.RepeatBox1.dataSource = deger;
                Pages.Page2.RepeatBox1.Label1.text = deger.AdiSoyadi;

            }
    
            
        });

        wc.run(true);
    
    }


Solution

  • I think your header is wrong, it should be
    requestHeaders : ["Content-Type:applictaion/json"]

    But the real problem I see, is the way you get your response, it should be:
    deger = JSON.parse(this.responseText);

    There's a guide about REST in Smartface in this link:
    https://www.smartface.io/developer/guides/data-network/rest-services-2/

    [Edit]

    Oh, that's quite different :)
    To achieve this, create the repeatBox with the Label inside it and define the dataSource property of the repeatBox. Then, on the onRowRender method, define the text of the Label as yourReponseText[e.rowIndex] (if your reponse isn't an array, transform it).

    Example:

    //Tranform the Object to an array
    var responseArray = [];
    
    for (var p in responseText) {
      responseArray.push(responseText[p]);
    }
    
    yourRepeatBox.dataSource = responseArray;
    yourRepeatBox.onRowRender = function(e) {
        this.controls[0].text = responseArray[e.rowIndex];
    }