如何使用Scala Anorm获取export default class RepsPage extends Component {
renderRep(repID){
var rep = new Firebase('https://ballot-app.firebaseio.com/congressPerson');
var nameView;
var partyView;
//entire function not executing?
rep.orderByChild("bioguideId").equalTo(repID).on("child_added", function(snapshot) {
console.log(snapshot.val());
nameView = <View style ={styles.tagContainer}>
<Text>{snapshot.val().name}</Text>
<Text>{snapshot.val().party}</Text>
</View>
});
return (
nameView
);
}
render(){
var user = this.props.user;
var reps = user.representatives;
return (
<ScrollView
automaticallyAdjustContentInsets={false}
scrollEventThrottle={200}
style={styles.scrollView}
>
{ reps.map(this.renderRep.bind(this)) }
</ScrollView>
);
}
}
值?我试过了:
user_name
而且,我得到的是 val result = SQL("SELECT user_name a FROM user WHERE user_id = {user_id}").on('user_id -> 1).executeQuery()
println("result ="+result)
,而不是我期待表中的result = SqlQueryResult(FlattenedManagedResource[?](...),false)
值。
我该怎样做才能得到我想要的东西?
答案 0 :(得分:1)
您必须使用结果解析器;例如
import anorm.SqlParser.scalar
val parser = scalar[String].single
// expect only one row (single),
// with only one column (scalar),
// of type String
val user: String = SQL("SELECT user_name a FROM user WHERE user_id = {user_id}").on('user_id -> 1).as(parser)
建议您查看documentation