How to work with JSON data indirectly through a Falcor Model. The Falcor Model allows the same familiar JavaScript path syntax with data using the. However the Model uses a push API, sending the data to a callback rather than returning it immediately. Using A push API means that's can move your data anywhere in the network later on, without changing the data retrieval C Ode in your client.
Below the code, show the data stay in memory, and we get the data by JavaScript path:
<!--index.html -<HTML><Head> <!--Do _not_ rely on the this URL in production. Use only during development. - <Scriptsrc= "//netflix.github.io/falcor/build/falcor.browser.js"></Script> <Script> varModel={people: [{name:"Zhentian", titles: [{ID:123, Name:"Developer", Rating:Ten}]}, {name:"Otto", titles: [{ID:321, Name:"Developer", Rating:Ten } ] } ] }; Console.log (model.people[0].titles[0].name); </Script></Head><Body></Body></HTML>
You'll see the ' Developer ' in the console.
Using Farcol. Model to the data async, the data would be pushed into the console:
<!--index.html -<HTML><Head> <!--Do _not_ rely on the this URL in production. Use only during development. - <Scriptsrc= "//netflix.github.io/falcor/build/falcor.browser.js"></Script> <Script> varModel= NewFalcor. Model ({cache: {people: [{name:"Zhentian", titles: [{ID:123, Name:"Developer", Rating:Ten } ] }, { Name:"Otto", titles: [{ID:321, Name:"Developer", Rating:Ten } ] } ] } }); Model.getvalue ('People[0].titles[0].name'). Then (function(value) {Console.log ("Falcor:", value); }); </Script></Head><Body></Body></HTML>
We still use the JavaScript path the repersent the data:
' People[0].titles[0].name '
GetValue return a promise, so we use. Then to get the value:
Model.getvalue (' People[0].titles[0].name ') . Then (function (value) { Console.log ( "Falcor:", value); });
[Falcor] Indroduce to Model