我可以使用 protected override void Request(Request request, IObserver<Response> observer)
{
query.Arrive += p => QueryReceive(request.RequestId, p, observer, query);
query.Error += (type, s, message) => QueryError(observer, message);
query.NoMoreData += id => QueryCompleted(observer);
query.Execute(request);
}
private void QueryError(IObserver<PositionSheetResponse> observer, string message)
{
observer.OnError(new Exception(message));
}
private void QueryCompleted(IObserver<PositionSheetResponse> observer)
{
observer.OnCompleted();
}
private void QueryReceive(Guid requestId, Qry0079Receive receiveData, IObserver<PositionSheetResponse> observer, IQry0079PositionSheet query)
{
observer.OnNext(ConvertToResponse(requestId, receiveData));
}
:include
对json-response进行to_json
ass:
def stats
@orders = Order.all
respond_to do |format|
format.json { render :json => @orders.to_json(:include => :review) }
end
end
它运作正常,但如果我需要多个变量的关联怎么办?
此:
def stats
@orders = Order.all
@tasks = Task.all
respond_to do |format|
format.json { render :json => {
orders: @orders.to_json(:include => :review),
tasks: @tasks.to_json(:include => :user)
}
}
end
end
答案 0 :(得分:0)
你可以试试这个。请参阅以下示例
<强> e.g。强>
ActiveSupport::JSON.decode(orders)
将Json字符串解码为Hash。
答案 1 :(得分:0)
这是jbuilder开始的情况,它是Rails 4中默认的ruby gem