2015-10-14 117 views
1

我和Falcor一起玩,看看我工作的公司是否可以使用它,所以我是一个新手。Falcor - 深层嵌套参考

我使用模型作为数据源。

这是我的模型:

var model = new falcor.Model({ 
    cache:{ 
    currenciesById: { 
     "1": { code: "USD", format: "$" }, 
     "2": { code: "GBP", format: "£" }, 
     "3": { code: "EUR", format: "€" }, 
     "4": { code: "YEN", format: "¥"} 
    }, 
    validCurrencies: { 
     "1": { $type: "ref", value: ["currenciesById", 1] }, 
     "2": { $type: "ref", value: ["currenciesById", 2] }, 
     "3": { $type: "ref", value: ["currenciesById", 3] }, 
     "4": { $type: "ref", value: ["currenciesById", 4] } 
    }, 
    quotesByPart: { 
     "100" : {price: 1768.34, currency: { $type: "ref", value: ["currencyById", 1] }}, 
     "200" : {price: 2834.44, currency: { $type: "ref", value: ["currencyById", 2] }}, 
     "201" : {price: 7803.54, currency: { $type: "ref", value: ["currencyById", 3] }}, 
     "347" : {price: 389.09, currency: { $type: "ref", value: ["currencyById", 4] }} 
    }, 
    quotes: { 
     "1": { $type: "ref", value: ["quotesByPart", 100] }, 
     "2": { $type: "ref", value: ["quotesByPart", 200] }, 
     "307": { $type: "ref", value: ["quotesByPart", 347] } 
    }, 
    reservedQuotes:{ 
     "1": { $type: "ref", value: ["quotesByPart", 201] } 
    } 
    } 
}); 

当我提出这个要求:

get('quotes[307].["price", "currency"]') 

这是Falcor的回应:

{ 
    "json": { 
     "quotes": { 
     "307": { 
      "price": 389.09, 
      "currency": [ 
       "currencyById", 
       4 
      ] 
     } 
     } 
    } 
} 

这就是我expencting。 Falcor发现引号[307]实际上是对quotesByPart [347]的引用并解析它,实际上它会返回正确的价格和对货币的参考。

然后,我试图让Falcor解决同一个请求中的第二个参考 - 货币。 我试着写这样的要求:

get('quotes[307].["currency"].["code"]') 

,或者出于绝望

get('quotes[307].["currency.code"]') 

的,我不能让Falcor解决第二个参考。

有人能告诉我我在这里错过了什么吗?

回答

1

问题是我的模型。

正确的模型是下面这个:

var model = new falcor.Model({ 
    cache:{ 
    currencyById: { 
     "1": { code: "USD", format: "$" }, 
     "2": { code: "GBP", format: "£" }, 
     "3": { code: "EUR", format: "€" }, 
     "4": { code: "YEN", format: "¥"} 
    }, 
    validCurrencies: { 
     "1": { $type: "ref", value: ["currencyById", 1] }, 
     "2": { $type: "ref", value: ["currencyById", 2] }, 
     "3": { $type: "ref", value: ["currencyById", 3] }, 
     "4": { $type: "ref", value: ["currencyById", 4] } 
    }, 
    quotesByPart: { 
     "100" : {price: 1768.34, currency: { $type: "ref", value: ["currencyById", 1] }}, 
     "200" : {price: 2834.44, currency: { $type: "ref", value: ["currencyById", 2] }}, 
     "201" : {price: 7803.54, currency: { $type: "ref", value: ["currencyById", 3] }}, 
     "347" : {price: 389.09, currency: { $type: "ref", value: ["currencyById", 4] }} 
    }, 
    quotes: { 
     "1": { $type: "ref", value: ["quotesByPart", 100] }, 
     "2": { $type: "ref", value: ["quotesByPart", 200] }, 
     "307": { $type: "ref", value: ["quotesByPart", 347] } 
    }, 
    reservedQuotes:{ 
     "1": { $type: "ref", value: ["quotesByPart", 201] } 
    } 
    } 
}); 

有这位模特Falcor按预期工作,甚至深嵌套引用得到解决。

+0

问题是'currencyById'应该是'currencyById'?好的,语法是用来获得报价的'价格',还有'货币'的'代码'和'格式'的语法是什么?它是'get('quotes [307]。[“price”,“currency.code”,“currency.format”]')'? Falcor Paths的文件仍然缺乏...... – jordanb