레코드 목록 뷰에 추가 작업을 추가했습니다. SugarCRM : REST 엔드 포인트에서 json 데이터를 가져 오는 방법
custom/modules/Opportunities/clients/base/views/recordlist/recordlist.js:
({
extendsFrom: 'RecordlistView',
initialize: function(options) {
this._super("initialize", [options]);
//add listener for custom button
this.context.on('list:opportunitiesexport2:fire', this.export2, this);
},
export2: function() {
//gets an array of ids of all selected opportunities
var selected = this.context.get("mass_collection").pluck('id');
if (selected) {
return App.api.call('read',
App.api.buildURL('Opportunities/Export2'),
{'selected_ids':selected},
{
success: function(response) {
console.log("SUCCESS");
console.log(response);
},
error: function(response) {
console.log('ERROR');
console.log(response);
},
complete: function(response){
console.log("COMPLETE");
console.log(response);
},
error: function(response){
console.log("ERROR");
console.log(response);
}
});
}
},
})
여기
http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_7.7/Integration/Web_Services/v10/Extending_Endpoints/ 튜토리얼은 엔드 포인트를 작성하는 방법을 설명합니다.
그러나 json 데이터 (선택된 ID의 문자열로 정렬 된 배열)를 얻는 방법은 설명하지 않습니다.
custom/modules/Opportunities/clients/base/api/OpportunitiesApi.php:
class OpportunitiesApi extends SugarApi
{
public function registerApiRest()
{
return array(
//GET
'MyGetEndpoint' => array(
//request type
'reqType' => 'GET',
//set authentication
'noLoginRequired' => false,
//endpoint path
'path' => array('Opportunities', 'Export2'),
//endpoint variables
'pathVars' => array('', ''),
//method to call
'method' => 'Export2',
//short help string to be displayed in the help documentation
'shortHelp' => 'Export',
//long help to be displayed in the help documentation
'longHelp' => 'custom/clients/base/api/help/MyEndPoint_MyGetEndPoint_help.html',
),
);
}
/**
* Method to be used for my MyEndpoint/GetExample endpoint
*/
public function Export2($api, $args)
{
//how to access $args['selected_ids']?
}
}
$args
는
Array
(
[__sugar_url] => v10/Opportunities/Export2
)
는 JSON 데이터를 액세스 할 수 있습니다 포함?