我想为一个聊天室应用一个过滤器,使得我只看到与该聊天室显示的外键关系的消息,所以我试图将shownMessages
传递给视图。我如何有效地做到这一点?我正在处理的当前错误是Error: [$resource:badcfg] Error in resource configuration for action
findById . Expected response to contain an object but got an array
。我尽可能地搜索,尽管如此,没有任何可用的。Loopback + Angular:findById错误。预期的响应包含一个对象,但得到了一个数组
// for inside the room
// node - injection order is extremely important
.controller('InsideRoomController', ['$scope', '$q', 'ChatRoom', 'ChatMessage', '$stateParams', '$state', function($scope, $q,
ChatRoom, ChatMessage, $stateParams, $state) {
// we include Chatroom as a param to the controller and func since we work with that to display it's contents
// only show messages pertaining to that room
$scope.shownMessages = [];
ChatMessage
.findById({ id: $stateParams.messagesInChat })
.$promise
.then(function(showMessages) { // once we query to find chat rooms
$scope.shownMessages = shownMessages;
});
}])
relationsInChat
是我在回送聊天室和ChatMessage之间作出foriegn键关系这是在chat-room.json
产生的名称:
{
"name": "ChatRoom",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"name": {
"type": "string",
"required": true
},
"city": {
"type": "string"
}
},
"validations": [],
"relations": {
"ChatMessagers": {
"type": "hasMany",
"model": "ChatMessager",
"foreignKey": ""
},
"chatMessages": {
"type": "hasMany",
"model": "ChatMessage",
"foreignKey": "messagesInChat"
}
},
"acls": [],
"methods": {}
}
编辑:我如何获得属于聊天的所有消息通过外键?我试图使用stateparams,但不知道如何
通过ID方法的发现,可能是** ** ID PARAM得到一些其他的值,而不是数量,所以在控制台什么$ stateParam正在恢复 –
好感谢检查,我越来越不确定 –
我米只是不知道如何获得属于通过外键聊天的所有消息在这一点..我试图使用stateparams,但不知道如何 –