【问题标题】:Get value from Table on Azure Mobile Service从 Azure 移动服务上的表中获取价值
【发布时间】:2016-01-26 14:04:54
【问题描述】:

我为我的英语语言道歉。 我按照 Azure 移动服务的计划编写了一个小脚本。

它应该检查我表中的特定值。但我只是 node.js 的新手,所以我真的无法弄清楚这些东西。

我找到了一个很好的例子,如何根据查询从表中获取一行。但是你能告诉我,我怎样才能得到特定的“细胞”?

var azure = require('azure');
exports.getActive = function (success, failure) {
    // azure.tables doesn't work either
    // tables no go
    tables.getTable('mytable').where({ active: true }).read(
        {
            success: function (results) {
                var result;
                if (results.length > 0) {
                    result = results[0];
                    success(result);

                } else {
                    failure("error");
                }

            },
            error: function (err) {
                failure(err);
            }
        }
        );
}

如果你能给我推荐一些关于这些东西的好文章,我会非常高兴。

【问题讨论】:

  • 这段代码是运行在 API 还是表中?您是从其他地方调用它,还是期望服务会为您调用它?

标签: node.js azure azure-mobile-services


【解决方案1】:

在 Node.js 后端移动服务中,我们可以利用移动服务在 node.js 运行时中定义的多个全局模块。

通常,在移动服务计划作业中,您可以使用 tables object 从脚本访问表。

tables.getTable 函数返回一个表对象实例,它是访问所请求表的代理。然后,您可以调用代理上的函数来访问和更改数据。

您可以参考the section How to: Access tables from scripts of the doc Work with a JavaScript backend mobile service了解更多信息。

这是我的测试代码sn-p。

function testsql() {
    // work with tables object
    var todoItemsTable = tables.getTable('TodoItem');
    todoItemsTable.read({
        success:function(data){
        console.log(data)
    }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-18
    • 2016-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多