[AC-5418] Alloys Data Binding with formFactor property
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Resolved |
Resolution | Done |
Resolution Date | 2017-12-13T21:06:54.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Alloy, Titanium SDK & CLI |
Labels | n/a |
Reporter | Alessandro Galvagno |
Assignee | Shak Hossain |
Created | 2017-12-01T11:44:25.000+0000 |
Updated | 2017-12-13T21:06:54.000+0000 |
Description
The following example fails if using the formFactor attribute.
<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>
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]();
}
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
File | Date | Size |
---|---|---|
Schermata 2017-12-06 alle 09.52.40.png | 2017-12-06T08:54:12.000+0000 | 5844 |
Test.zip | 2017-12-04T12:10:10.000+0000 | 10047820 |
Hello, Can you please attach a sample app with the sample code inside, what we can directly use to test the issue? that will be helpful. Thanks.
I created an ad-hoc project. If you run it in "Run Mode" on a real iOS device you can reproduce the error.
[^Test.zip]
Hello! I could not reproduce this issue with the following environment and your provided test case. Mac OS X: v10.13.1 Ti SDK: 6.3.0.GA iPhone 5s v11.1.1 Node: v8.9.0 I can run App successfully. Thanks
Hello, have you start the project on a real device? Did you select "Run" instead of "Debug" when you start the project? Thanks. !Schermata 2017-12-06 alle 09.52.40.png|thumbnail!
[~agalvagno] Yes, I did the same. I just downloaded the Test.zip file then use the App folder in my App. I did not include any other file and it runs successfully. Can you do that same for testing? Mac OS X: v10.13.1 Ti SDK: 6.3.0.GA, 7.0.0.GA iPhone 5s v11.1.1 Node: v8.9.0 Thanks
Hello, I have reinstalled everything, I have updated Appcelerator Studio to the latest version 5.0 and SDK to version 7.0.0.GA and it seems that the problem has been solved. I will do other tests to be sure. Thank you for the support.