Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Ajith-Pandian/50038e48298088f46554f387a64230aa to your computer and use it in GitHub Desktop.
Save Ajith-Pandian/50038e48298088f46554f387a64230aa to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Picker,
Item,
Button,
AsyncStorage,
TextInput,
ListView
} from 'react-native';
import BackgroundImage from './BackgroundImage';
var global = require('./Globals');
import Login from './Login';
let size ;
var accountArray = [] ;
var account ;
var listItem = [];
import api from './api';
const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
export default class Balance extends Component{
constructor(props,context){
super(props);
this.state ={
cifNumber :'',
id:'',
fullname :'',
accountList :[],
value : '',
text:'',
dataSource: ds,
};
this.setState=({
cifNumber:global.cifNumber
})
//AsyncStorage.getItem('user')
//this.ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
}
updateFullname = (value) => {
this.setState({
fullname : value
});
}
updateCifNumber = (value) =>{
this.setState({
cifNumber :value
});
}
getAccountList = ()=>{
/*updateCifNumber(global.cifNumber);
updateFullname(global.fullname);*/
fetch("http://10.0.2.2:8080/MobileBanking/rest/user/listRekeningCekSaldo",{
method:'POST',
headers:{
'Accept': 'application/json',
'Content-Type': 'application/json'
},body :JSON.stringify({
//cifNumber : global.cifNumber,
cifNumber:'12345'
})
}).then((response) => response.json())
.then((responseJson) => {
//alert(JSON.stringify(responseJson.listRekening));
//alert(responseJson.listRekening.length);
alert(responseJson.listRekening);
size = responseJson.listRekening.length;
alert(size);
for(var i = 0 ; i< size ;i++){
account = responseJson.listRekening[i];
accountArray.push(account);
this.setState({
dataSource : ds.cloneWithRows(responseJson.listRekening),
})
}
return responseJson;
})
.catch((error)=> {
console.error(error);
});
}
getBalancebyAccount = () => {
fetch("http://10.0.2.2:8080/MobileBanking/rest/user/cekSaldoByRekening",{
method:'POST',
headers:{
'Accept': 'application/json',
'Content-Type': 'application/json'
},body:JSON.stringify({
nomorRekening :this.state.account,
})
}).then((response) => response.json())
.then((responseJson)=>{
alert(JSON.stringify(responseJson));
}).catch((error)=>{
console.error(error);
})
}
render(){
for(var i = 0 ; i< size ;i++){
listItem.push(
<Item label = "accountArray[i]" value = "accountArray[i]"/>
)
}
return(
<BackgroundImage>
<View>
{this.getAccountList}
<ListView dataSource= {this.state.dataSource}
renderRow = {(rowData) => <Text>{rowData.noAccout}</Text>}
/>
<TextInput onChangeText = {(text) => this.updateCifNumber.bind(this)} />
<Button title="getAccountList" color="blue" onPress = {this.getAccountList.bind(this)}/>
<Button title="getBalance" color="blue" onPress = {this.getBalancebyAccount.bind(this)}/>
<Picker selectedValue ={listItem}
onValueChange = {(itemValue,itemIndex) => this.setState({
accountList:itemValue
})}>
{listItem}
</Picker>
</View>
</BackgroundImage>
);
}
}
const styles = StyleSheet.create({
text :{
color:'white',
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment