トピック一覧の取得
アプリケーションスコープのトピック一覧の取得
アプリケーションスコープの全てのトピックを一覧として取得することができます。トピックの件数が 50 件を超える場合は、ページネーションによって複数回にわけて一覧を取得する必要があります。
以下に、アプリケーションスコープに存在するトピックの一覧を取得する例を挙げます。
-
function listAll(userProc) { var listRecurr = function(params) { var topicList = params[0]; var nextPaginationKey = params[1]; userProc(topicList); if (nextPaginationKey == null) { return Promise.resolve(); } // Get the next page of the topic list. return Kii.listTopics(null, nextPaginationKey); }; // Get the first page of the topic list. return Kii.listTopics().then(listRecurr); } // Get a topic list. listAll(function(topicList) { for (var i = 0; i < topicList.length; i++) { // Do something. var topic = topicList[i]; } }).catch( function(error) { // Handle the error. var errorString = error.message; } );
-
var listCallbacks = { success: function(topicList, nextPaginationKey) { for (var i = 0; i < topicList.length; i++) { // Do something. var topic = topicList[i]; } if (nextPaginationKey != null) { // Get the next page of the topic list. Kii.listTopics(listCallbacks, nextPaginationKey); } }, failure: function(errorString) { // Handle the error. } } // Get the first page of the topic list. Kii.listTopics(listCallbacks);
ここでは、以下の処理を実行しています。
listTopics
メソッドを実行し、トピック一覧を取得します。nextPaginationKey
をチェックして取得しきれなかったトピックがあるか確認し、ある場合はnextPaginationKey
を引数に再度、listTopics
メソッドを実行します。
グループスコープのトピック一覧の取得
グループスコープの全てのトピックを一覧として取得することができます。トピックの件数が 50 件を超える場合は、ページネーションによって複数回にわけて一覧を取得する必要があります。
以下に、グループスコープに存在するトピックの一覧を取得する例を挙げます。
-
function listAll(group, userProc) { var listRecurr = function(params) { var topicList = params[0]; var nextPaginationKey = params[1]; userProc(topicList); if (nextPaginationKey == null) { return Promise.resolve(); } // Get the next page of the topic list. return group.listTopics(null, nextPaginationKey).then(listRecurr); }; // Get the first page of the topic list. return group.listTopics().then(listRecurr); } // Instantiate an existing group. var group = KiiGroup.groupWithURI("Set the URI of an existing group here"); // Get a topic list. listAll(group, function(topicList) { for (var i = 0; i < topicList.length; i++) { // Do something. var topic = topicList[i]; } }).catch( function(error) { // Handle the error. var theGroup = error.target; var errorString = error.message; } );
-
// Instantiate an existing group. var group = KiiGroup.groupWithURI("Set the URI of an existing group here"); var listCallbacks = { success: function(topicList, nextPaginationKey) { for (var i = 0; i < topicList.length; i++) { // Do something. var topic = topicList[i]; } if (nextPaginationKey != null) { // Get the next page of the topic list. group.listTopics(listCallbacks, nextPaginationKey); } }, failure: function(errorString) { // Handle the error. } } // Get the first page of the topic list. group.listTopics(listCallbacks);
ここでは、以下の処理を実行しています。
listTopics
メソッドを実行し、トピック一覧を取得します。nextPaginationKey
をチェックして取得しきれなかったトピックがあるか確認し、ある場合はnextPaginationKey
を引数に再度、listTopics
メソッドを実行します。
ユーザースコープのトピック一覧の取得
ユーザースコープの全てのトピックを一覧として取得することができます。トピックの件数が 50 件を超える場合は、ページネーションによって複数回にわけて一覧を取得する必要があります。
以下に、ユーザースコープに存在するトピックの一覧を取得する例を挙げます。
-
function listAll(user, userProc) { var listRecurr = function(params) { var topicList = params[0]; var nextPaginationKey = params[1]; userProc(topicList); if (nextPaginationKey == null) { return Promise.resolve(); } // Get the next page of the topic list. return user.listTopics(null, nextPaginationKey).then(listRecurr); }; // Get the first page of the topic list. return user.listTopics().then(listRecurr); } // Get the currently logged-in user. var user = KiiUser.getCurrentUser(); // Get a topic list. listAll(user, function(topicList) { for (var i = 0; i < topicList.length; i++) { // Do something. var topic = topicList[i]; } }).catch( function(error) { // Handle the error. var theUser = error.target; var errorString = error.message; } );
-
// Get the currently logged-in user. var user = KiiUser.getCurrentUser(); var listCallbacks = { success: function(topicList, nextPaginationKey) { for (var i = 0; i < topicList.length; i++) { // Do something. var topic = topicList[i]; } if (nextPaginationKey != null) { // Get the next page of the topic list. user.listTopics(listCallbacks, nextPaginationKey); } }, failure: function(errorString) { // Handle the error. } } // Get the first page of the topic list. user.listTopics(listCallbacks);
ここでは以下の処理を実行しています。
listTopics
メソッドを実行し、トピック一覧を取得します。nextPaginationKey
をチェックして取得しきれなかったトピックがあるか確認し、ある場合はnextPaginationKey
を引数に再度、listTopics
メソッドを実行します。