Chinese Documentation : fields(字段)过滤器

字段过滤器置顶哪些属性include在结果中或者exclude在结果中。

REST API

filter[fields][propertyName]=<true|false>&filter[fields][propertyName]=<true|false>...
注意这里有多个filter

可以只用stringified JSON format 做为REST query。

Node API

Icon

Methods of models in the AngularJS client have a different signature than those of the Node API. For more information, see AngularJS SDK API.

{ fields: {propertyName: <true|false>, propertyName: <true|false>, ... } }
Where:

  • propertyName 是你要include或者exclude属性的属性名
  • <true|false> 标示是include还是exclude。true代表include,false代表exclude。
    可以使用1表示true,0表示false。

默认情况下,查询会返回模型的所有字段。注意了,如果你使用字段过滤器include了一个字段,那么query将只include你这个字段,这意味模型的其它字段都是exclude的。

例子

只返回模型的id,make,model属性:

REST
?filter[fields][id]=true&filter[fields][make]=true&filter[fields][model]=true
Node API
{ fields: {id: true, make: true, model: true} }

返回:

[
  {
    "id": "1",
    "make": "Nissan",
    "model": "Titan"
  },
  {
    "id": "2",
    "make": "Nissan",
    "model": "Avalon"
  },
  ...
]

Exclude vin属性:

REST
?filter[fields][vin]=false
Node API
{ fields: {vin: false} }