Backbone.js 钛合金中的where条件问题
如何根据条件获取值,我尝试了以下方法Backbone.js 钛合金中的where条件问题,backbone.js,titanium,titanium-mobile,fetch,titanium-alloy,Backbone.js,Titanium,Titanium Mobile,Fetch,Titanium Alloy,如何根据条件获取值,我尝试了以下方法 var countrynames = Alloy.Collections.countryDetails; countrynames.fetch({languageID: 1}); countrynames.on("reset", function() { var countrynamesLength = countrynames.length, column = Ti.UI.createPickerColumn(); for (va
var countrynames = Alloy.Collections.countryDetails;
countrynames.fetch({languageID: 1});
countrynames.on("reset", function() {
var countrynamesLength = countrynames.length,
column = Ti.UI.createPickerColumn();
for (var i = 0; i < countrynamesLength; i++) {
var row = Ti.UI.createPickerRow({
title: countrynames.at(i).get("countryText")
});
column.addRow(row);
}
$.countryPicker.columns = [column];
});
countrynames.fetch({languageID: 1});
var countrynames=Alloy.Collections.countryDetails;
countrynames.fetch({languageID:1});
countrynames.on(“重置”,函数(){
var countrynamesLength=countrynames.length,
column=Ti.UI.createPickerColumn();
对于(变量i=0;i
但上述情况并未过滤该条件。它正在从表中获取所有值。如何为上述代码使用where条件
请提供任何建议。收集获取方法只需从表中获取数据
//grab all data no filter here.
countrynames.fetch({
success:function(){
Ti.API.info('fetched');
},
error:function(){
Ti.API.info('not fetched');
}
});
方法根据过滤器获取特定数据并返回JavaScript数组的集合
//grab data where languageID == 1
countrynames.fetch();
var filtered=countrynames.where({
languageID: 1
});
//use data
Ti.API.info('filtered[0] =='+ JSON.stringify(filtered[0]));
可以使用查询参数组合这两种方法
countrynames.fetch({
query::"SELECT * FROM countrynames(just put your table name here) WHERE languageID ='1';"
});
所以你可以得到一个包含过滤数据的合金集合
countrynames.each(function(model){
Ti.API.info('model '+ JSON.stringify(model));
});
对不起,我的英语…谢谢,它很好用。。一个小面团如何更新id=1的表中的一行;您应该使用
get
var yourmodel=collection.get({id:1})
然后使用set
yourmodel.set({filedToUpdate:value})编码>然后保存它yourmodel.save()代码>。。。你必须问另一个问题…这是更新查询问题的链接,请提供一些答案。