![](/img/trans.png)
[英]Why doesn't my angular-js jsonp request work when querying solr
[英]Querying relations in loopback doesn't work via Angular SDK
我正在嘗試查詢一個模型關系,我有兩個模型1.工人2.技能
工人有很多技能
我可以通過資源管理器http:// localhost:3000 / explorer /#!/ Workers / prototype_get_skills和/ api / Worker /:id / Skills網址查詢api,它會返回給定工人ID的技能列表
當我嘗試調用Angular SDK生成的Worker.skills()方法時,出現404未找到錯誤,就會發生此問題
以下是我有的Angular實現
angular.module('worker-dashboard').factory('WorkerDashboardSkillService',['Worker',
function(Worker){
function getWorkerSkills(worker){
return Worker.skills({
filter:
{
where:
{
"workerId" : worker
}
}
},function(data){
console.log(data);
},
function(err){
console.log(err);
})
}
function addWorkerSkills(worker,skill){
return Worker.skills.create(
{
"skillName": skill.name,
//TODO chabge below
"skillCategory": skill.name,
"workerId": worker
},function(data){
console.log(data);
},
function(err){
console.log(err);
})
}
return{
getWorkerSkills : getWorkerSkills,
addWorkerSkills : addWorkerSkills
}
}]);
我還嘗試了一個示例loopback-getting-started-intermediate
有一個例子
$scope.reviews = Review.find({
filter: {
where: {
publisherId: $rootScope.currentUser.id
},
include: [
'coffeeShop',
'reviewer'
]
}
});
但是這個例子看起來像是屬於歸屬關系,當我嘗試修改它無法做到時
編輯:添加Worker.json
{
"name": "Worker",
"base": "User",
"idInjection": true,
"properties": {
"workerName": {
"type": "string"
},
"workerFirstName": {
"type": "string"
},
"workerLastName": {
"type": "string"
},
"isWorkerBlackListed": {
"type": "boolean"
},
"workerBlacklistedByClient": {
"type": [
"string"
]
}
},
"validations": [],
"relations": {
"skills": {
"type": "hasMany",
"model": "Skills",
"foreignKey": "workerId"
}
},
"acls": [
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW"
}
],
"methods": []
}
Skills.json
{
"name": "Skills",
"base": "PersistedModel",
"idInjection": true,
"properties": {
"skillName": {
"type": "string"
},
"skillCategory": {
"type": "string"
}
},
"validations": [],
"relations": {
"worker": {
"type": "belongsTo",
"model": "Worker",
"foreignKey": ""
}
},
"acls": [
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW"
}
],
"methods": []
}
遲到總比不到好。 今天我也遇到了同樣的麻煩。 您只需要添加角度依賴性。
angular
.module('app')
//inject all the model you need
.controller('ListBooksController', ['$scope', '$state', 'Book', 'Collection', 'Author', function($scope,
$state, Book, Collection, Author) {
$scope.books = Book.find({
filter: {
include: [
'author'
//put the model you want to retrieve
]
}
});
console.log($scope.books);
}])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.