【问题标题】:Issue with where condion in titanium alloy钛合金的位置问题
【发布时间】:2014-10-14 07:16:45
【问题描述】:

我们如何根据条件获取值,我尝试如下

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 条件。

请有任何建议..

【问题讨论】:

    标签: backbone.js titanium titanium-mobile fetch titanium-alloy


    【解决方案1】:

    collection fetch 方法只是从你的表中获取数据。

    //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(); ...你必须问另一个问题...
    • 这是更新查询问题的链接,请提出一些答案。 stackoverflow.com/questions/26333242/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多