- Access 用コンテンツ アプリ / Content apps for Access
- JavaScript API for Office (v1.1) / JavaScript API for Office (v1.1)
そしてこんな感じになる。
"レコード移動時 / OnCurrent" や "レコード更新時 / AfterUpdate"などイベントでフィールドの値が取れたりすればいいかなと。
/// <reference path="../App.js" /> (function () { "use strict"; Office.initialize = function (reason) { $(document).ready(function () { app.initialize(); $('#set-row').click(setRowToBindingTable); $('#add-row').click(addRowToBindingTable); displayDataOrBinding(); }); }; function displayDataOrBinding() { Office.context.document.bindings.getByIdAsync( app.bindingID, function (result) { if (result.status === Office.AsyncResultStatus.Succeeded) { var binding = result.value; addEventHandlerToBinding(binding); onBindingSelectionChanged(); } else { addBindingFromPrompt(); } }); }; // Displays UI that lets the user specify a selection to bind to. // Bindings.addFromPromptAsync method (JavaScript API for Office v1.1) // http://msdn.microsoft.com/en-us/library/fp142201%28v=office.1501401%29.aspx function addBindingFromPrompt() { Office.context.document.bindings.addFromPromptAsync( Office.BindingType.Table, { id: app.bindingID }, function (result) { if (result.status === Office.AsyncResultStatus.Succeeded) { var binding = result.value; onBindingSelectionChanged(); addEventHandlerToBinding(binding); } else { app.showNotification(result.error.name, result.error.message); }; }); } // Adds a handler to the binding for the specified event type. // Binding.addHandlerAsync method (JavaScript API for Office v1.1) // http://msdn.microsoft.com/en-us/library/fp142201%28v=office.1501401%29.aspx function addEventHandlerToBinding(binding) { binding.addHandlerAsync( Office.EventType.BindingSelectionChanged, onBindingSelectionChanged ); binding.addHandlerAsync( Office.EventType.BindingDataChanged, onBindingDataChenged ); } // AfterUpdate function onBindingDataChenged() { Office.select("bindings#" + app.bindingID).getDataAsync( {rows: "thisRow"}, function (result) { var currentRow = result.value; app.showNotification('DataChanged', currentRow.rows[0][0]); }); } // onCurrent function onBindingSelectionChanged() { Office.select("bindings#" + app.bindingID).getDataAsync( {rows: "thisRow" }, function (result) { var curentRow = result.value; app.showNotification('SelectionChanged',curentRow.rows[0][0]); }); } // edit function setRowToBindingTable() { Office.select("bindings#" + app.bindingID).setDataAsync( [['Nagoya']], { rows: "thisRow" }, function (result) { app.showNotification('SetRow', result.status); }); } // add function addRowToBindingTable() { Office.context.document.bindings.getByIdAsync( app.bindingID, function (result) { var binding = result.value; binding.addRowsAsync([["Gunma"]]); }); } })();
/* 共通のアプリ機能 */ var app = (function () { "use strict"; var app = {}; app.bindingID = 'myBinding'; // (各ページから呼び出す) 共通の初期化関数 app.initialize = function () { $('body').append( '<div id="notification-message">' + '<div class="padding">' + '<div id="notification-message-close"></div>' + '<div id="notification-message-header"></div>' + '<div id="notification-message-body"></div>' + '</div>' + '</div>'); $('#notification-message-close').click(function () { $('#notification-message').hide(); }); // 初期化後に、共通の通知関数を公開します app.showNotification = function (header, text) { $('#notification-message-header').text(header); $('#notification-message-body').text(text); $('#notification-message').slideDown('fast'); }; }; return app; })();まぁなんとか動く。
Binding.setDataAsync メソッドは、AsyncResult オブジェクトの件でもう少し確認していく必要があるかもと。だけど、新規レコードの追加って必要のかな。
0 件のコメント:
コメントを投稿