如何在Azure移动服务的javascript后端获取系统属性__CreatedAt,__ Version?

时间:2014-06-25 10:23:50

标签: javascript azure azure-mobile-services

我试图从我的表中显式获取系统属性,但它无法正常工作。我可以看到,如果我使用https://myservice.azure-mobile.net/tables/todoitem?__systemProperties= *,则URL会返回包括这些字段在内的所有数据,但在代码上我无法将其作为项目.__ version或item.version。我尝试添加todoitemtable = WindowsAzure.MobileServiceTable.SystemProperties.All;但没有成功!我还查看了http://azure.microsoft.com/en-us/documentation/articles/mobile-services-html-validate-modify-data-server-scripts/,但这是添加新列而不是使用现有系统列。

$(function(){     var client = new WindowsAzure.MobileServiceClient('https://ib-svc-01.azure-mobile.net/','key');     var todoItemTable = client.getTable('todoitem'); // = WindowsAzure.MobileServiceTable.SystemProperties.All;

// Read current data and rebuild UI.
// If you plan to generate complex UIs like this, consider using a JavaScript templating library.
function refreshTodoItems() {
    var query = todoItemTable.where({ complete: false });

    query.read().then(function(todoItems) {
        var listItems = $.map(todoItems, function(item) {
            return $('<li>')
                .attr('data-todoitem-id', item.id)
                .append($('<button class="item-delete">Delete</button>'))
                .append($('<input type="checkbox" class="item-complete">').prop('checked', item.complete))
                .append($('<div>').append($('<input class="item-text">').val(item.id))
        .append($('<span class="timestamp">' 
                + (item.createdAt && item.createdAt.toDateString() + ' '
                + item.createdAt.toLocaleTimeString() || '') 
                + '</span>')));
        });

        $('#todo-items').empty().append(listItems).toggle(listItems.length > 0);
        $('#summary').html('<strong>' + todoItems.length + '</strong> item(s)');
    }, handleError);
}

function handleError(error) {
    var text = error + (error.request ? ' - ' + error.request.status : '');
    $('#errorlog').append($('<li>').text(text));
}

function getTodoItemId(formElement) {
    return $(formElement).closest('li').attr('data-todoitem-id');
}

// Handle insert
$('#add-item').submit(function(evt) {
    var textbox = $('#new-item-text'),
        itemText = textbox.val();
    if (itemText !== '') {
        todoItemTable.insert({ text: itemText, complete: false }).then(refreshTodoItems, handleError);
    }
    textbox.val('').focus();
    evt.preventDefault();
});

// Handle update
$(document.body).on('change', '.item-text', function() {
    var newText = $(this).val();
    todoItemTable.update({ id: getTodoItemId(this), text: newText }).then(null, handleError);
});

$(document.body).on('change', '.item-complete', function() {
    var isComplete = $(this).prop('checked');
    todoItemTable.update({ id: getTodoItemId(this), complete: isComplete }).then(refreshTodoItems, handleError);
});

// Handle delete
$(document.body).on('click', '.item-delete', function () {
    todoItemTable.del({ id: getTodoItemId(this) }).then(refreshTodoItems, handleError);
});

// On initial load, start by fetching the current data
refreshTodoItems();

});

1 个答案:

答案 0 :(得分:2)

我试图从API脚本中访问系统属性并找到它并认为它有用且相关:http://www.brandonmartinez.com/2014/10/22/retrieve-system-properties-in-azure-mobile-services-javascript-backend/

基本上你可以这样做(例子来自帖子):

myTable.read({
        systemProperties: ['__createdAt', '__updatedAt'],
        success: function(tableEntries) {
        // So on and so forth
    }
}