search json from the value entered in the search bar

You must Login before you can answer or comment on any questions.

Hello,

I want to make the custom rows for the values which are entered in the search bar and are present in the json. Like i entered Subway(places_name in json) in the search bar , then i want to make the rows only for subway not for any other place_name . it should show only the details of subway .

I tried the following code but not working.

var search = Titanium.UI.createSearchBar({
    barColor:'#CCCCCC',
    showCancel:true,
    height:45,
    top:47,
    hintText:'Search'
    });
 
    win.add(search);
 
search.addEventListener('return',function(){
 
        var url="http://184.95.33.26/~staging/site_admin/api/places.php?format=json";
            xhr = Titanium.Network.createHTTPClient();
            xhr.open('GET',url);
            xhr.onload = function(){
                renderV2(JSON.parse(this.responseText.replace(/\\n/gi,"")));
        }
        xhr.send();
});
 
function renderV2(e){
 
    var result_window=Ti.UI.createWindow({
        backgroundImage:'pic/bg.png',
            barColor:'#327ed3',
        titleImage:'pics/top_bar_logo.png'
 
    });
 
 
    Titanium.UI.currentTab.open(result_window);
    var venues=e;
    var data=[];
 
    Ti.API.info(venues.length);
 
    for (var c = 0; c < venues.length; c++) {
 
        if(search.value=venues[c].places_name){
 
        var sTitle = venues[c].places_name;
 
        Ti.API.info(sTitle);
        var row = Ti.UI.createTableViewRow({
            height : 100,
            id:c
        });
        var view = Ti.UI.createView({
            width:310,
            height:90,
            backgroundColor:'#fff',
            borderColor:'#a9abae',
            borderRadius:10,
            borderWidth:1,
            id:c
        });
        row.add(view);
 
 
        var label = Ti.UI.createLabel({
            text : sTitle,
            left : 10,
            top : 10,
            color : '#4a4a4a',
            height : 20,
            width : 220,
            font:{
                fontSize:15,
                fontWeight:'bold'
            },
            id:c
        });
        var sLocation = '';
 
        sLocation = venues[c].places_street_no + ' ' + venues[c].places_street_name + ' ' + venues[c].places_street_type;
        Ti.API.info(sLocation);
        var supplimentryText = Ti.UI.createLabel({
            text : sLocation,
            left : 10,
            top : 30,
            font : {
                fontSize : 11
            },
            color : '#808285',
            height : 20,
            width : 220,
            id:c
        });
        view.add(supplimentryText);
        view.add(label);
 
 
        data.push(row);
        Ti.API.info(data.length);
        }
    }//for loop ends
 
    var tableview = Ti.UI.createTableView({
    separatorColor:'transparent'
    });
 
    tableview.setData(data);
    result_window.add(tableview);
}

Your Answer

Think you can help? Login to answer this question!