我想爲一個聊天室應用一個過濾器,使得我只看到與該聊天室顯示的外鍵關係的消息,所以我試圖將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,但不知道如何 –