[Falcor] Indroduce to Model

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.