API群集 - 使用自定义组配置默认端点

时间:2016-01-28 09:18:13

标签: javascript api endpoint apicluster

我正在使用Api Cluster库。当我尝试创建多个export class RecipientListViewComponent { arrAll: Recipient[]; constructor(private recipientsService: RecipientsService, params: RouteParams, private router: Router) { this.arrAll = recipientsService.getAll(); } newRecipient() { this.router.navigate(['../NewRecipient']); } deleteRecipients() { //need to know which recipients are checked let selected = this.arrAll.filter((x) => x.selected) console.log(selected); } checkbox(recipient) { recipient.selected = (recipient.selected) ? false : true; } } 时,我可能只想使用默认的endpoint group模式,但配置选项可能不同。

  

情景:如果我没有提及“端点”'在组中,则应从默认值'端点'中获取值。图案

请查看此代码click here

2 个答案:

答案 0 :(得分:1)

问题在第164行(ApiCluster.js)

ApiCluster.generated = ApiCluster.data.apiUrls[groupName][name];

它试图获得' empDetails'来自v1群。

ApiCluster.generated = ApiCluster.data.apiUrls [' v1'] [' empDetails']

修复方法是将行更改为

ApiCluster.generated = ApiCluster.data.apiUrls[groupName] && ApiCluster.data.apiUrls[groupName][name] ? ApiCluster.data.apiUrls[groupName][name] : ApiCluster.data.apiUrls[ApiCluster.data.defaultGroupName][name];

因此,如果该属性在请求的组中不可用,那么它将从默认值中读取它。

以下是修复的网址:
http://plnkr.co/edit/ys6btxjYH0xqh1kGuOVf?p=preview

答案 1 :(得分:1)

这是API Cluster 1.0.5 JS库中的限制之一。

由于API Cluster 1.0.5期望addAnother / defaults方法参数需要以下三个必选项。

  1. 名称
  2. 配置
  3. 端点
  4.   

    Defaults / addAnother方法创建端点组,每个组都是独立的

    请尝试以下方式解决您的问题。

    ApiCluster
      .defaults({
        name: 'mydefault',
    
        config: {
          'employee': 'emp',
          'details': 'defaultDetails',
          'timesheet': 'timesheet'
        },
    
        endpoints: {
          "empDetails": "_employee_/_details_/:empId/profile"
        }
      })
      .addAnother({
        name: 'v1',
        config: {
          'employee': 'emp',
          'details': 'v1Details',
          'timesheet': 'timesheet'
        },
    
        endpoints: {
          "empDetails": "_employee_/_details_/:empId/profile"
        }
      });
    
    var empDetailURL = ApiCluster
      .use('v1')
      .get('empDetails')
      .arg({
        'empId': 1000
      })
      .query({
        'confirm': 'yes',
        'testAccount': 'yes'
      })
      .url();