zoukankan      html  css  js  c++  java
  • [Falcor] Return the data from server

    <!-- index.html -->
    <html>
    <head>
        <!-- Do _not_  rely on this URL in production. Use only during development.  -->
        <script src="//netflix.github.io/falcor/build/falcor.browser.js"></script>
        <script>
            var model = new falcor.Model( {
                source: new falcor.HttpDataSource( '/model.json' )
            } );
    
            // retrieve the "greeting" key from the root of the Virtual JSON resource
            model.getValue( 'genreList[0].titles[0].name' )
                 .then( function ( json ) {
                     console.log( JSON.stringify( json, null, 3 ) );
                 } )
        </script>
    </head>
    <body>
    </body>
    </html>
    var falcorExpress = require( 'falcor-express' );
    var falcor = require('falcor');
    var express = require( 'express' );
    var app = express();
    
    var $ref = falcor.Model.ref;
    var model = new falcor.Model({
        cache: {
            titleById: {
                5221: {
                    name: "House of Cards",
                    rating: {$type: "atom", value: 5},
                    bookmark: {$type: "error", value: "Something went wrong."}
                }
            },
            genreList: [
                {
                    name: 'Recently Watched',
                    titles: [
                        $ref("titleById[5221]")
                    ]
                },
                {
                    name: "New Releases",
                    titles: [
                        $ref("titleById[5221]")
                    ]
                }
            ]
        }
    });
    
    
    
    app.use(express.static(__dirname + '/'));
    app.use( '/model.json', falcorExpress.dataSourceRoute( function ( req, res ) {
        return model.asDataSource();
    } ) );
    
    var server = app.listen(3131);
  • 相关阅读:
    LeetCode 10 Regular Expression Matching(字符串匹配)
    LeetCode 9 Palindrome Number(回文数字判断)
    操作系统期末复习资料分享
    计算机网络那些事~(二)
    seL4之hello-3征途
    计算机网络那些事~(一)
    seL4之hello-2旅途(完成更新)
    博客声明
    seL4环境配置
    Canvas链式操作
  • 原文地址:https://www.cnblogs.com/Answer1215/p/5085845.html
Copyright © 2011-2022 走看看