当前位置: 首页 > 工具软件 > Falcor > 使用案例 >

[Falcor] Return the data from server

寿子轩
2023-12-01
<!-- 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);

 

转载于:https://www.cnblogs.com/Answer1215/p/5085845.html

相关阅读

相关文章

相关问答