Loopback REST连接器,数据映射响应模型?

时间:2016-03-14 20:11:03

标签: rest datasource loopbackjs strongloop

我已经设置了一个简单的"产品" model(即{id:" string"," name":string,etc})并使用REST连接器将数据源设置为远程URL,该URL返回包含数十个字段的JSON blob ,如何将远程响应中的字段映射到本地模型?每当我执行我的方法时,我都会从遥控器中取回原始响应....我至少期望得到一个空模型的模型。

enter image description here

1 个答案:

答案 0 :(得分:1)

我非常确定您必须覆盖模型上的find()方法并手动执行此映射工作。

这样的事情:

def magic_n(guess2):
    magicn = 7
    tries = 0
    while (tries < 5) and (guess2 != magicn):
        if guess2 < 7:
            tries += 1
            print("Too Low")
            guess2 = int(input("Give me another number since the last one was too high : "))
        elif guess2 > 7:
            tries += 1
            print("Too high")
            guess2 = int(input("Give me another number since the l ast one was too low : "))
        else:
            print("Good job you got it")