如何在环回中访问其他模型的功能?

时间:2019-02-15 11:54:03

标签: node.js post loopbackjs loopback

我有两个模型Place和Tag。我在tag.js中创建了creteTag()远程方法,我想在place.js中访问此函数。

tag.js

'use strict';
var request = require('request');
module.exports = function(Tag) {
Tag.crateaTag = function(name, callback) {
    request({
        method: 'POST',
        url: 'http://localhost:3000/api/tags',
        body:{
            "name": name
        },
        json: true
     },
     function (error, response,body) {
        if (error || response.statusCode != 200) {
           console.log('Hiba' + error + ' \n' + response);
        }
        callback(error, body);
     });
};

place.js

'use strict';
var request = require('request');
module.exports = function(Place) {
var app = require('../../server/server');
Place.createPlace = function(name, descreption, tagName, callback) {
    var Tag = app.models.Tag; //???

    request({
        method: 'POST',
        url: 'http://localhost:3000/api/tags',
        body:{
            "name": name,
            "descreption": descreption,
            "tag": Tag.createTag(tagName) //???
        },
        json: true
     },
     function (error, response, body) {
        if (error || response.statusCode != 200) {
           console.log('Hiba' + error + ' \n' + response);
        }
        callback(error, body);
     });
  };
};

我想在数据库中发布想要查看单独集合的标签。

1 个答案:

答案 0 :(得分:0)

tag.js 中将 #: import FadeTransition kivy.uix.screenmanager.FadeTransition # Reference main.py #: import main main #: import Slider kivy.uix.slider #: import ActionBar kivy.uix.actionbar #: import Window kivy.core.window ScreenController: transition: FadeTransition() HomeScreen: OptionsScreen: TutorialScreen: <HomeScreen> name: 'home' BoxLayout: id:'hem' orientation:'vertical' BoxLayout: size_hint_x: 1 orientation:'horizontal' canvas: Color: rgba: 0,1,0,1 Rectangle size: self.size pos: self.pos BoxLayout: orientation:'horizontal' BoxLayout: size_hint_x: .5 orientation:'horizontal' canvas: Color: rgba: 1,0,1,1 Rectangle size: self.size pos: self.pos BoxLayout: size_hint_x: .5 orientation:'horizontal' canvas: Color: rgba: 1,1,0,1 Rectangle size: self.size pos: self.pos ActionBar: pos_hint: {'top':1} ActionView: use_separator: True ActionPrevious: title: 'Fredde & Kribbas kivy' with_previous: False ActionOverflow: ActionGroup: text: 'Group1' ActionButton: text: 'home' on_touch_down: app.root.current = 'home' ActionButton: text: 'Options' on_touch_down: app.root.current = 'option' ActionButton: text: 'Tutorial' on_touch_down: app.root.current = 'tut' <OptionsScreen> name: 'option' BoxLayout: orientation:'vertical' BoxLayout: orientation:'horizontal' size_hint_y: 1/3 Label: text:'Text size' font_size: textsize.value size_hint_x:.5 Slider: id:textsize min: 5 max: 25 value:15 step: 1 size_hint_x:.5 BoxLayout: #fontsize checkbox orientation:'horizontal' size_hint_y: 1/3 BoxLayout: orientation:'vertical' Label: text: 'Nightmode' CheckBox: id:default size_hint_y: None active: True height:'50dp' group:'g1' BoxLayout: orientation:'vertical' Label: text: 'Daymode' CheckBox: id:stor size_hint_y: None height:'50dp' group:'g1' BoxLayout: orientation:'horizontal' size_hint_y: 1/3 canvas: Color: rgba: 0,0,1,1 Rectangle size: self.size pos: self.pos ActionBar: pos_hint: {'top':1} ActionView: use_separator: True ActionPrevious: title: 'Fredde & Kribbas kivy' with_previous: False ActionOverflow: ActionGroup: text: 'Group1' ActionButton: text: 'home' on_touch_down: app.root.current = 'home' ActionButton: text: 'Options' on_touch_down: app.root.current = 'option' ActionButton: text: 'Tutorial' on_touch_down: app.root.current = 'tut' <TutorialScreen> name: 'tut' ActionBar: pos_hint: {'top':1} ActionView: use_separator: True ActionPrevious: title: 'Fredde & Kribbas kivy' with_previous: False ActionOverflow: ActionGroup: text: 'Group1' ActionButton: text: 'home' on_touch_down: app.root.current = 'home' ActionButton: text: 'Options' on_touch_down: app.root.current = 'option' ActionButton: text: 'Tutorial' on_touch_down: app.root.current = 'tut' 声明为远程方法:

crateaTag

place.js 中,将Tag.remoteMethod('crateaTag', { accepts: { arg: 'name', type: 'string', required: true }, description: "create a tag" }); 用作:

Tag
相关问题