【发布时间】:2017-03-10 05:48:23
【问题描述】:
我正在尝试为聊天室应用过滤器,以便我只看到与显示的聊天室具有外键关系的消息,因此我尝试将 shownMessages 传递给视图。我如何有效地做到这一点?我正在处理的当前错误是Error: [$resource:badcfg] Error in resource configuration for actionfindById. Expected response to contain an object but got an array。我正在尽我所能搜索,但仍然无济于事。
// 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 是我在 chat-room.json 中生成的 ChatRoom 和 ChatMessage 之间的环回中的外键关系的名称:
{
"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 但不确定如何
【问题讨论】:
-
在 find by id 方法中,可能是 id 参数获取了其他值而不是数字,因此请在控制台中检查 $stateParam 返回的内容
-
好的,谢谢,我越来越不确定了
-
我现在只是不确定如何通过外键获取属于聊天的所有消息。我正在尝试使用 stateparams 但不确定如何
-
我可能需要某种 where 子句