Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 如何从包含模型中筛选环回中的字段?_Angularjs_Loopbackjs - Fatal编程技术网

Angularjs 如何从包含模型中筛选环回中的字段?

Angularjs 如何从包含模型中筛选环回中的字段?,angularjs,loopbackjs,Angularjs,Loopbackjs,我有一个疑问: UserModel.find({ filter: { include: [ "communications", "roles" ], where : { "object_type" : 1 } } }, function(data){ $rootScope.users = data; }); 我想

我有一个疑问:

UserModel.find({

    filter: {
        include: 
        [
            "communications",
             "roles"
        ],
        where : {
            "object_type" : 1
        }
    } 
}, function(data){
    $rootScope.users = data;
});
我想通过字段“object_type”从通信模型过滤器中获取所有数据,但它不能按我所希望的那样工作

我的通信模型如下所示:

...
"properties": {
"object_type": {
  "type": "number"
},
"object_id": {
  "type": "number"
},
"communications_type_code": {
  "type": "number"
},
"address_type": {
  "type": "number"
},
"contact_value": {
  "type": "string"
},
"notes": {
  "type": "string"
},
....
UserModel.find({
    include: [ "communications", "roles" ],
    where : { "object_type" : 1 }
}, function(data){
    $rootScope.users = data;
});

Oded,我相信您不需要搜索参数中的
filter
属性。应该是这样写的:

...
"properties": {
"object_type": {
  "type": "number"
},
"object_id": {
  "type": "number"
},
"communications_type_code": {
  "type": "number"
},
"address_type": {
  "type": "number"
},
"contact_value": {
  "type": "string"
},
"notes": {
  "type": "string"
},
....
UserModel.find({
    include: [ "communications", "roles" ],
    where : { "object_type" : 1 }
}, function(data){
    $rootScope.users = data;
});

还要确保添加到
中的其他实体包括
与查询的模型有关系。是真的
UserModel
还是应该是
communicationmodel

要查询相关模型,您必须使用关系范围。在您的情况下,可能是这样的:

UserModel.find({
    filter: {
        include: 
        [
            {
              "relation": "communications",
              "scope": { 
                "where": {"object_type": 1}
              }

            },
            "roles"
        ]
    } 
}, function(data){
    $rootScope.users = data;
});
检查有关的文档