如何从服务器脚本中的另一个表中选择数据? Windows Azure

时间:2012-11-26 19:36:35

标签: javascript azure azure-storage azure-mobile-services

我在使用Windows Azure移动服务。我有2个表计划1:N订阅(一个计划有许多订阅相关,订阅有一个计划相关)。我不太熟悉JS服务器脚本。当我插入新的Subscripton时,我需要查询此新订阅具有的计划(planId来自订阅对象中的客户端)。所以我就是这样:

function insert(item, user, request) 
{
    var planTable = tables.getTable("Plan");
    //Here I want to select the plan from planTable using item.PlanId

    request.execute();
}

2 个答案:

答案 0 :(得分:3)

您可以这样做(官方文档可用here):

 planTable.where({
        id: item.PlanId
    }).read({
        success: function(results) {
            // Do something here!
            request.execute();
        }
    });

答案 1 :(得分:2)

您可以在http://blogs.msdn.com/b/carlosfigueira/archive/2012/09/11/supporting-complex-types-in-azure-mobile-services-clients-implementing-1-n-table-relationships.aspx的博客文章中找到这种情况。它包含了扩展Sandrino Di Mattia答案的例子。