So, basically I am working on an app for a basketball league. In this part of the app, I am allowing the user to be able to search. I am currently putting in 2 parameters for the search, a button to select which State, and another for which role (Player, coach, etc) they are searching for. I will probably add searching by name later.
I am running into 2 issues. First, when the search does the GET call to my API, it pulls in the JSON correctly, but for some reason it is only adding the first entry of the json into my search array in the app. I have done this before, but for some odd reason its not working here.
Also, even with it adding in that first entry into the search array in the app, its not showing up on the UI. Am I missing something to make it update as it searches? I hope these questions make sense.
Here is Javascript code for the search call, and the UI code (sorry if the code doesnt copy in correctly.):
Javascript:
roleSelected.onValueChanged(module, search);
stateSelected.onValueChanged(module, search);
function search() {
var url = encodeURI(Backend.rootURL + stateSelected.value + “/” + roleSelected.value + “.json”);
console.log(url)
fetch(url).then(function(response) {
console.log(JSON.stringify(response));
return response.json();
}).then(function(json) {
var searchJSON = json;
var keys = Object.keys(searchJSON);
keys.forEach(function(x) {
searchResults.add(new Result(searchJSON[x]));
console.log(JSON.stringify(searchResults.value));
});
function Result(data) {
this.name = data.name;
this.email = data.email;
}
});
// console.log(JSON.stringify(searchResults.value));
};
UX:
<ScrollView>
<StackPanel>
<Text Alignment=“HorizontalCenter” FontSize=“30” Margin=“0,20,0,20” >Search</Text>
<CBL.SearchDropdown ux:Name=“stateDropDown” Items="{states}" Value="{stateSelected}" Width=“40” Margin=“10” />
<CBL.SearchDropdown ux:Name=“roleDropDown” Items="{roles}" Value="{roleSelected}" Width=“120” Margin=“10” />
<Each Items="{searchResults}" >
<Separator Margin=“0,10,0,0” />
<Panel HitTestMode=“LocalBoundsAndChildren” Clicked="{listClick}">
<CBL.Text Value="{name}" Margin=“20” />
<WhilePressed>
<Scale Factor=".95" Duration=".08" Easing=“QuadraticOut” />
</WhilePressed>
</Panel>
</Each>
<Separator />
</StackPanel>
</ScrollView>