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

Adding backbone.js initialize() function to an Alloy model

$
0
0

Latest version of Studio, SDK 3.2.2 GA Build targets: Android, mobile web. Host: Linux Mint 14

Using a standard Alloy-generated model.

exports.definition = {
    config: {
        columns: {
            "name": "text",
            "address": "text"
        },
        adapter: {
            type: "properties",
            collection_name: "user"
        }
    },
    extendModel: function(Model) {
        _.extend(Model.prototype, {
            // extended functions and properties go here
        });
 
        return Model;
    },
    extendCollection: function(Collection) {
        _.extend(Collection.prototype, {
            // extended functions and properties go here
        });
 
        return Collection;
    }
};
Want to create a model and set a property in a controller:
var user = Alloy.createModel('user');
    user.set({name: "Test Value"});
 
    // user.name is still undefined.
Or - trying it this way:
initialize: function() {
    this.name = 'Test value';       
        }
All this seems real basic. Should be able to say user.set({name: 'Test Value'});

Have also tried adding a backbonejs initialize():

  1. As a property under config.

  2. As a property under exports.definition.

These are routine operations with backbone.js. Anyone see anything obvious?


Viewing all articles
Browse latest Browse all 8068

Trending Articles



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