[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);
上一篇:安装 SSL 证书


下一篇:h5应用缓存及收藏时Icon显示