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的更多相关文章

  1. Spring Boot笔记一

    Spring Boot 入门 Spring Boot 简介 > 简化Spring应用开发的一个框架:> 整个Spring技术栈的一个大整合:> J2EE开发的一站式解决方案: 微服务 ...

  2. Netflix Falcor获取JSON数据

    Netflix开源了JavaScript库Falcor,它为从多个来源获取JSON数据提供了模型和异步机制. Netflix利用Falcor库实现通过JSON数据填充他们网页应用的用户界面.所有来自内 ...

  3. [Falcor] Intro to JSON Graph

    JSON is a very commonly used data interchange format. Unfortunately while most application domain mo ...

  4. [Falcor] Retrieving Multiple Values

    In addition to being able to retrieve a path from a Falcor Model, you can also retrieve multiple Pat ...

  5. [Falcor] Return the data from server

    <!-- index.html --> <html> <head> <!-- Do _not_ rely on this URL in production. ...

  6. Falcor 学习一基本使用

    falcor 是netflix 公司为了解决自己api数据查询所开发的查询框架,很不错(尽管netflix 也在用graphql )以下是falcor 的 一个简单使用,基于express 框架,使用 ...

  7. 【疯狂造轮子-iOS】JSON转Model系列之二

    [疯狂造轮子-iOS]JSON转Model系列之二 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 上一篇<[疯狂造轮子-iOS]JSON转Model系列之一> ...

  8. 【疯狂造轮子-iOS】JSON转Model系列之一

    [疯狂造轮子-iOS]JSON转Model系列之一 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 之前一直看别人的源码,虽然对自己提升比较大,但毕竟不是自己写的,很容易遗 ...

  9. 详解树莓派Model B+控制蜂鸣器演奏乐曲

    步进电机以及无源蜂鸣器这些都需要脉冲信号才能够驱动,这里将用GPIO的PWM接口驱动无源蜂鸣器弹奏乐曲,本文基于树莓派Mode B+,其他版本树莓派实现时需参照相关资料进行修改! 1 预备知识 1.1 ...

随机推荐

  1. PHP+MySQL中对UTF-8,UTF8(utf8),set names gbk 的理解

    问题一:在我们进行数据库操作时会发现,数据库中表的编码用的是utf-8,但是在进行dos命令是要使用set names gbk (一)Mysql中默认字符集设置有四级:服务器级,数据库级,表级,和字段 ...

  2. 微信开发python+django两个月的成功经历,django是个好框架!

        时间:大三 上学期没有用微信内置浏览器而纯对话开发,坑了自己好一下. 下学期选错bottle框架,以为轻量好,谁知开发中什么都自己来很痛苦. 选对了框架django,终于在大三最后的个把月里写 ...

  3. 页面插入Flash方式

    法一 <!-- 播放Flash动画代码 --> <div class="logoFlash"> <object classid="clsid ...

  4. absolut绝对定位的非绝对定位用法

    一.absolute绝对定位的流行用法 一般而言,我们会用absolute绝对定位做什么呢?就是绝对定位,顾名思意,定死在某个位置上.例如,lightbox效果就是使用的绝对定位,例如新浪微博的弹出提 ...

  5. Apache配置域名

    Apache配置域名 在WIN下安装APACHE配置虚拟目录和UNIN下基本是一样的就是修改httpd.conf1:单个IP对应单个域名例如:www.phpunion.com对应192.168.1.1 ...

  6. js+dom开发第十六天

    一.css常用标签及页面布局 1.常用标签 position(定位) z-index(定位多层顺序) background(背景) text-align(针对字符自动左右居中) margin(外边距) ...

  7. python之加密

    import hashlib obj = hashlib.md5(bytes('adfasfasdfsfasf',encoding = 'utf-8')) obj.update(bytes('123' ...

  8. MapReduce程序开发之流量求和(八)

    1.分析记录手机流量的日志. 2.拿到日志中的一行数据,切分各个字段,抽取出我们需要的字段:手机号,上行流量,下行流量,然后封装成kv发送出去 3.使用java中的map方法: public clas ...

  9. 3ds max 2016 新功能

    3ds max 2016 新功能_MCG节点编辑器 这是介绍视频下载: http://pan.baidu.com/s/1gds4wqJ

  10. 关于Weblogic Server(介绍)

    Weblogic, 美国Oracle公司名下产品,是一个基于 J2EE 架构.可扩展的应用服务器. 本文档选取部分官方文档翻译 总览 支持多种类型的分布式应用 基于 SOA 应用的理想架构 完整实现 ...