【问题标题】:Titanium Alloy Backbone and ACS钛合金主干和ACS
【发布时间】:2014-05-09 16:26:12
【问题描述】:

我正在尝试将数据从 Appcelerator 云服务传递到主干模型。我找不到有关如何执行此操作的文档...

以下是我的模型文件中的配置:

exports.definition = {
    config: {
        "columns": {
            "id":"integer",
            "address":"text",
            "user_completed":"integer"
        },
        "adapter": {
            "type": "", //what can I enter?
            "collection_name": "places"
        }
    },
    extendModel : function(Model) {
        _.extend(Model.prototype, {
            validate : function(attrs) {
                for (var key in attrs) {
                    var value = attrs[key];
                    if (value) {
                        if (key === "item") {
                            if (value.length <= 0) {
                                return 'Error: No item!';
                            }
                        }
                        if (key === "done") {
                            if (value.length <= 0) {
                                return 'Error: No completed flag!';
                            }
                        }
                    }
                }
            }
        });

        return Model;
    },

    extendCollection : function(Collection) {
        _.extend(Collection.prototype, {
            comparator: function(places) {
                return places.get('done');
            }
        });

        return Collection;
    }
};

如何从 ACS 传递数据?

【问题讨论】:

    标签: javascript android ios backbone.js titanium-alloy


    【解决方案1】:

    您需要在配置中使用“acs”。

    检查一下:

    exports.definition = {
    config: {
        "columns": {
            "id":"integer",
            "address":"text",
            "user_completed":"integer"
        },
        "adapter": {
            "type": "acs",  // Use "acs"
            "collection_name": "places"
        }
    },
    extendModel : function(Model) {
        _.extend(Model.prototype, {
            validate : function(attrs) {
                for (var key in attrs) {
                    var value = attrs[key];
                    if (value) {
                        if (key === "item") {
                            if (value.length <= 0) {
                                return 'Error: No item!';
                            }
                        }
                        if (key === "done") {
                            if (value.length <= 0) {
                                return 'Error: No completed flag!';
                            }
                        }
                    }
                }
            }
        });
    
        return Model;
    },
    
    extendCollection : function(Collection) {
        _.extend(Collection.prototype, {
            comparator: function(places) {
                return places.get('done');
            }
        });
    
        return Collection;
    }
    };
    

    查看此演示文稿:Titanium presentation 在 ACS 主题下,标题为“ACS in Alloy”。

    另外,这里是示例:Alloy backbone & ACS

    希望这会有所帮助。

    【讨论】:

    • 谢谢。 ACS 是新同步适配器的名称,但必须创建才能工作。我遇到了 aaronksaunders 的示例,但适配器似乎过于复杂。希望 Titanium 将在他们的下一次更新中添加一个 ACS 适配器......
    • 这对你有用吗?如果是,请接受答案:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多