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. 【转】javascript变量作用域、匿名函数及闭包

    下面这段话为摘抄,看到网上大多数人使用的是变量在使用的时候声明而不是在顶端声明,也可能考虑到js查找变量影响性能的问题,哪里用就在哪里声明,也很好. 在Javascript中,我们在写函数的时候往往需 ...

  2. Python 的“+”和append在添加字符串时候的区别

    对于一个空的Python列表,往后添加内容有很多种,其中两种一个是用“+”直接添加内容,另外一种是Listname.append(x)来添加内容 其中,如果处理字符串 在使用“+”的时候,会将字符串拆 ...

  3. Fresco 多图加载之ResizeOptions

    引言 最近圈子开发工作比较重再加上寒冬已至,所以停了两个月没写,手有点生,好吧,这都是借口,我承认-( ̄▽ ̄-),下面回归正题. 一般地在使用Fresco图片的时候,无需担心图片大小的问题,因为 通常 ...

  4. 单个ViewController支持横屏,其他全竖屏方法-b

    如果项目中用了navigationViewController, 那么就应该新建一个uinavigationViewController的子类,然后在这个类里面写上下面的代码,在使用的时候就用自定义的 ...

  5. 转载:.NET Web开发技术简单整理

    在最初学习一些编程语言.一些编程技术的时候,做的更多的是如何使用该技术,如何更好的使用该技术解决问题,而没有去关注它的相关性.关注它的理论支持,这种学习技术的方式是短平快.其实工作中有时候也是这样,公 ...

  6. Flip Game

    http://poj.org/problem?id=1753 #include<cstdio> #include<algorithm> #include<string.h ...

  7. UVA 10706 Number Sequence (找规律 + 打表 + 查找)

    Problem B Number Sequence Input: standard input Output: standard output Time Limit: 1 second A singl ...

  8. find the mincost route(floyd变形 无向图最小环)

    Time Limit: 1000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...

  9. 一键源码安装Ansible

    #!/bin/bash # @Name:install_ansible.sh # @Author:Eivllom # @Create -- # @Modify -- app_soft="/a ...

  10. Search Insert Position——LeetCode

    Given a sorted array and a target value, return the index if the target is found. If not, return the ...