Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

How to call a custom funciton from Model in alloy framework

$
0
0

I have a file Model/user.js

user.js:
 
 
    exports.definition = {
    config : {
        "columns" : {
            "id"            : "INTEGER PRIMARY KEY AUTOINCREMENT",
            "email"         : "TEXT",
            "verify_code"           : "TEXT",
            "password_hashed"       : "TEXT",
            "token_key"             : "TEXT",
            "user_id"       : "INTEGER",
            "language"      : "TEXT NULL",
            "nick"          : "TEXT",
            "fullname"      : "TEXT",
            "gender"        : "int NULL",
            "avatar"        : "TEXT NULL",
            "bio"           : "TEXT NULL",
            "ext"           : "int NULL",
            "last_login"            : "DATETIME NULL",
            "created_at"            : "DATETIME NULL",
            "updated_at"            : "DATETIME NULL",
            "update_time"           : "TEXT NULL" 
        },
        adapter : {
            // type: "localStorage",
            type            : "sql",
            collection_name : "User",
            idAttribute     : "id"
        }
    },
    extendModel : function(Model) {
        _.extend(Model.prototype, {
            // extended functions and properties go here
            validate : function(attrs) {
                for (var key in attrs) {
                    var value = attrs[key];
                    if (key === "id") {
                        if (value.length <= 0) return "Error: No id!";
                    }
                    if (key === "user_name") {
                        if (value.length <= 0) return "Error: No user name!";
                    }
                    if (key === "pass_word") {
                        if (value.length <= 0) return "Error: No pass word!";
                    }
                    if (key === "points") {
                        if (value.length < 0)  return "Error: No points!";
                    }
                }
            },
            // Extend Backbone.Model
            customProperty : 'User',
            customFunction : function() {
                Ti.API.info('User model.');
                alert('kjfghjk');
            },
        });
 
        return Model;
    },
    extendCollection : function(Collection) {
        _.extend(Collection.prototype, {
            // extended functions and properties go here
            comparator : function(user) {
                return user.get('id');
 
            }
    });
        return Collection;
    }
    };
 
//----- Custom function here ------
    function add (a,b) {  return a+b;}
    exports.add = add;
I want call function add and use it into index.js

index.js:

// call funtion add here
 
 
       $.index.open();
can someone help me ! Thanks

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>