[Falcor] Indroduce to Model
How to work with JSON data indirectly through a Falcor Model. The Falcor Model allows you to work with data using the same familiar JavaScript path syntax. However the Model uses a push API, sending the data to a callback rather than returning it immediately. Using a push API means that you can move your data anywhere in the network later on, without changing the data retrieval code 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 this URL in production. Use only during development. -->
<script src="//netflix.github.io/falcor/build/falcor.browser.js"></script>
<script>
var model = {
people: [
{
name: "Zhentian",
titles: [
{
id: 123,
name: "developer",
rating: 10
}
]
},
{
name: "Otto",
titles: [
{
id: 321,
name: "developer",
rating: 10
}
]
}
]
}; console.log(model.people[0].titles[0].name);
</script>
</head>
<body>
</body>
</html>
You will see the "developer" in the console.
Using farcol.Model to the data async, the data will be pushed into the console:
<!-- 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({
cache: {
people: [
{
name: "Zhentian",
titles: [
{
id: 123,
name: "developer",
rating: 10
}
]
},
{
name: "Otto",
titles: [
{
id: 321,
name: "developer",
rating: 10
}
]
}
]
}
}); 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的更多相关文章
- Spring Boot笔记一
Spring Boot 入门 Spring Boot 简介 > 简化Spring应用开发的一个框架:> 整个Spring技术栈的一个大整合:> J2EE开发的一站式解决方案: 微服务 ...
- Netflix Falcor获取JSON数据
Netflix开源了JavaScript库Falcor,它为从多个来源获取JSON数据提供了模型和异步机制. Netflix利用Falcor库实现通过JSON数据填充他们网页应用的用户界面.所有来自内 ...
- [Falcor] Intro to JSON Graph
JSON is a very commonly used data interchange format. Unfortunately while most application domain mo ...
- [Falcor] Retrieving Multiple Values
In addition to being able to retrieve a path from a Falcor Model, you can also retrieve multiple Pat ...
- [Falcor] Return the data from server
<!-- index.html --> <html> <head> <!-- Do _not_ rely on this URL in production. ...
- Falcor 学习一基本使用
falcor 是netflix 公司为了解决自己api数据查询所开发的查询框架,很不错(尽管netflix 也在用graphql )以下是falcor 的 一个简单使用,基于express 框架,使用 ...
- 【疯狂造轮子-iOS】JSON转Model系列之二
[疯狂造轮子-iOS]JSON转Model系列之二 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 上一篇<[疯狂造轮子-iOS]JSON转Model系列之一> ...
- 【疯狂造轮子-iOS】JSON转Model系列之一
[疯狂造轮子-iOS]JSON转Model系列之一 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 之前一直看别人的源码,虽然对自己提升比较大,但毕竟不是自己写的,很容易遗 ...
- 详解树莓派Model B+控制蜂鸣器演奏乐曲
步进电机以及无源蜂鸣器这些都需要脉冲信号才能够驱动,这里将用GPIO的PWM接口驱动无源蜂鸣器弹奏乐曲,本文基于树莓派Mode B+,其他版本树莓派实现时需参照相关资料进行修改! 1 预备知识 1.1 ...
随机推荐
- ios开发之通知事件
每天学习一点点,总结一点点,成功从良好的习惯开始! 昨天学习了ios开发中的关于通知事件的一些东西,在这里简单总结下,仅供初学者学习,更多的是怕我自己忘了,咩哈哈~~~~ 通知(notificatio ...
- request 报错The remote server returned an error: (415) Unsupported Media Type.
开发时遇到个问题,程序访问数据库数据,给服务器发送请求时,老是报错,返回的错误页面是: HTTP Status 415 - Unsupported Media Type type Status rep ...
- DOS命令行使用pscp实现远程文件和文件夹传输(转)
转自 http://snailwarrior.blog.51cto.com/680306/141201 pscp是putty安装包所带的远程文件传输工具,使用和Linux下scp命令相似,具体的使 ...
- bzoj2734: [HNOI2012]集合选数
Description <集合论与图论>这门课程有一道作业题,要求同学们求出{1, 2, 3, 4, 5}的所有满足以 下条件的子集:若 x 在该子集中,则 2x 和 3x 不能在该子集中 ...
- Google测试精华文章(1) - 测试行为,而非实现
Your trusty Calculator class is one of your most popular open source projects, with many happy users ...
- BZOJ 1072 排列
Description 给一个数字串\(s\)和正整数\(d\), 统计\(s\)有多少种不同的排列能被\(d\)整除(可以有前导\(0\)).例如\(123434\)有\(90\)种排列能被\(2\ ...
- 巧用powerpoint制作符合期刊要求的复合图
- 零零碎碎搞了一天最后发现是ruby版本问题
查来查去查不到问题,后来在stackoverflow看到: http://stackoverflow.com/questions/22352838/ruby-gem-install-json-fail ...
- android小文章——手机照片上传服务器方法
手机上传:http://blog.csdn.net/bitter_2014/article/details/40618587
- Delphi 的各种错误信息(中英文)
******************************* * 编 译 错 误 信 息 * ******************************* ';' not allowed befo ...