Uploaded image for project: 'Appcelerator - INBOX'
  1. Appcelerator - INBOX
  2. AC-5418

Alloys Data Binding with formFactor property

    Details

    • Type: Bug
    • Status: Resolved
    • Resolution: Done
    • Affects Version/s: None
    • Component/s: Alloy, Titanium SDK & CLI
    • Labels:
      None
    • Environment:

      Description

      The following example fails if using the formFactor attribute.

      views/corsi.xml

      <Alloy>
      	<Collection src="Corsi"/>
      	<Window id="corsiWindow" class="container" formFactor="handheld">
      		<LeftNavButton>
              	<View layout="horizontal">
                  	<Button onClick="toggle"></Button>
                     	<Label id="title"></Label>
                  </View>                    
              </LeftNavButton>
              <View>
                  <ScrollableView id="scrollableview" dataCollection="Corsi">
                      <Require src="uiElement/corsiSlide"/>
                  </ScrollableView>
              </View>		
      	</Window>
      	<!--Tablet version-->
      	<View class="container" formFactor="tablet">		
              <View>
                  <ScrollableView id="scrollableview" dataCollection="Corsi">
                      <Require src="uiElement/corsiSlide"/>
                  </ScrollableView>
              </View>	
      	</View>
      </Alloy>
      

      controllers/corsi.js

      var args = arguments[0] || {};
      var collection = Alloy.Collections.Corsi;
       
      collection.fetch({
      	error : function(){
      		Alloy.Globals.loading.hide();
      	},
      	finish : function(collection, response) {
      		Alloy.Globals.loading.hide();
      	},
      	localData: true,
      	initFetchWithLocalData: true
      });
       
       
      function toggle(e) {
          var fn = 'toggleLeftWindow';
          Alloy.Globals.drawer[fn]();
      }
      

      models/Corsi.js

      var Mutators = require('vendor/backbone.mutators');
      var utils = require('ui/utils');
       
      exports.definition = {
          config : {        
              URL: "http://xxxx.com,
          	debug: 0, //debug mode enabled
          	useStrictValidation: 0, // validates each item if all columns are present
              adapter : {
                  type : "sqlrest",
                  collection_name : "corsi",
                  db_file : "/xeniasoft.sqlite",
                  db_name : "xeniasoft",
                  //idAttribute: "rowid",
                  remoteBackup : false            
              },        
         	 	initFetchWithLocalData : false,
          	disableSaveDataLocallyOnServerError : true,
          	localOnly: false,
          	deleteAllOnFetch: true,
          	parentNode: function (data) {
          		return JSON.parse(data);
      		}
          },
       
          extendModel: function(Model) {		
              _.extend(Model.prototype, {
                  // Extend, override or implement Backbone.Model 
                  mutators : {                
                      titolo : {
                          get : function() {
                              return "   " + this.get("corso") + "   ";
                          }, // get
                          transient : true
                      },
                      trainer : {
                          get : function() {
                              return L('istruttore') + this.get("istruttore").toUpperCase() + "   ";
                          }, // get
                          transient : true
                      },
                      image : {
                          get : function() {
                              return (this.get("foto") != "") ? this.get("foto") : "/images/placeholder_big.jpg";
                          }, // get
                          transient : true
                      },
                      imageList : {
                          get : function() {
                              return (this.get("foto") != "") ? this.get("foto") : "/images/placeholder.jpg";
                          }, // get
                          transient : true
                      },
      				lezioni : {
      					get : function() {
      						var sql = "SELECT * FROM lezioni WHERE id_corso=" + this.get("id_corso");
      						db = Ti.Database.open('xeniasoft');
      						var rs = db.execute(sql);
      						var output = [];
      						while (rs.isValidRow()) {
      							var g = utils.getGornoSettimana(rs.fieldByName('id_giorno')) + " " + rs.fieldByName("ora_inizio") + " - " + rs.fieldByName("ora_fine");
      							output.push(g);
      							rs.next();
      						}
      						rs.close();
      						db.close();
      						return output;
      					},
      					transient : true
      				}
                  }
              });
      		
              return Model;
          },
       
          extendCollection: function(Collection) {		
              _.extend(Collection.prototype, {
                  // Extend, override or implement Backbone.Collection 
      			getCorso : function(id) {
      				var collection = this;
      				
      				var sql = "SELECT * FROM " + collection.config.adapter.collection_name + " WHERE id_corso=" + id;
      				db = Ti.Database.open(collection.config.adapter.db_name);
      				var rs = db.execute(sql);
      				var output = [];
      				if(rs.isValidRow()) {
      					output.push({
      						imageList: (rs.fieldByName("foto") != "") ? rs.fieldByName("foto") : "/images/placeholder.jpg" ,
      						corso : rs.fieldByName("corso"),
      						descrizione : rs.fieldByName("descrizione"),
      						istruttore: rs.fieldByName("istruttore"),
      						sala : rs.fieldByName("sala"),
      						prenotabile : rs.fieldByName("prenotabile")
      					});
      				}
      				
      				rs.close();
      				db.close();
      				
      				return output;
      			}
              });
      		
              return Collection;
          }
      };
      

      This will generate the following code.

      ...
      {for(var d,f=a.opts||{},g=j.models,h=g.length,k=[],l=0;l<h;l++)
      ...
      

      If you run the application in "run mode" on a real device, the following error is displayed. In debugging this error is not generated.

      "undefined is not an object (evaluating 'j.models')";
      

        Attachments

          Activity

            People

            • Assignee:
              shossain Shak Hossain
              Reporter:
              agalvagno Alessandro Galvagno
            • Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Git Source Code