Javascript Falcor中不一致的结果

Javascript Falcor中不一致的结果,javascript,promise,netflix,falcor,Javascript,Promise,Netflix,Falcor,我一直在看Netflix Falcor演示项目,并修改了一个示例,其中添加了一个标题,然后立即删除了一个标题。但是,当我反复运行以下代码时,列表中删除后的最后一个标题(打印在“删除后的标题”)每次都不同 有时最后一个标题未定义,有时它仍然包含推式标题,有时添加新标题,导致标题列表随时间缓慢增长。这看起来很糟糕(或者我做错了什么?) 那是你在那里写的一些筑巢地狱!!考虑到如何使用x、length和index,您可能会像这样最小化嵌套(这不是一个答案,但可能是一个开始),这绝对是一个可怕的承诺代码返

我一直在看Netflix Falcor演示项目,并修改了一个示例,其中添加了一个标题,然后立即删除了一个标题。但是,当我反复运行以下代码时,列表中删除后的最后一个标题(打印在“删除后的标题”)每次都不同

有时最后一个标题未定义,有时它仍然包含推式标题,有时添加新标题,导致标题列表随时间缓慢增长。这看起来很糟糕(或者我做错了什么?)


那是你在那里写的一些筑巢地狱!!考虑到如何使用
x
length
index
,您可能会像这样最小化嵌套(这不是一个答案,但可能是一个开始),这绝对是一个可怕的承诺代码
返回每个回调的结果(或承诺)(对于
长度
索引
等变量,请参见),并将错误处理程序放在一个
中。最后,捕获(jerror)
model.get('genrelist[0].titles.length')
.then(function(z) {
    var length = z.json.genrelist[0].titles.length;
    model.getValue('genrelist[0].titles[0..' + length + '].name')
    .then(function(titles){
        console.log('titles before push:', titles);

        model.call('genrelist[0].titles.push',
            [{$type: "ref", value: ['titlesById', 3]}],
            ["name", "rating"], ["length"]
        ).then(function(x) {

            model.getValue('genrelist[0].titles[0..' + length + '].name')
            .then(function(titles){
                console.log('titles after push:', titles);
                var index = x.json.genrelist[0].titles.length - 1;
                model.call('genrelist[0].titles.remove', [index])
                .then(function(y) {

                    model.get('genrelist[0].titles[' + (index + 1) + ']["name", "year"]')
                    .then(function() {
                        model.get('genrelist[0].titles.length')
                        .then(function(w) {

                            model.getValue('genrelist[0].titles[0..' + length + '].name')
                            .then(function(titles){
                                console.log('titles after remove:', titles);
                            },jerror);
                        });
                    }, jerror);

                }, jerror);
            },jerror);
        }, jerror);
    },jerror);
}, jerror)