钛合金的条件问题

时间:2014-10-14 07:16:45

标签: 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 (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});

但以上并未过滤条件。它从表中获取所有值。如何使用上述代码的where条件。

请任何建议..

1 个答案:

答案 0 :(得分:1)

集合获取方法只是从表中获取数据。

//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));
});

抱歉我的英文......