Shawn
Shawn

Reputation: 3159

taffydb update not working

I am trying to update an existing record in a TAFFY database.

I insert a single record, then attempt to update it, but the update doesn't take.

var cSheetXref = TAFFY();

cSheetXref.insert({
  "ID":0,
  "vendor":"",
  "productType":"",
  "itemCode":"",
  "productName":"",
  "activeIngredient":"",
  "cost":"",
  "retailPrice":"",
  "um":"",
  "packagingSize":"",
  "rate":""
});     

$(document).on("click","#update",function(){
  var dbCol="itemCode";
  ttitle="example text";
  cSheetXref({"ID":0}).update({dbCol:ttitle});

  cSheetXref("ID",0).each(function (record,recordnumber) {          
    $("#results").html("");
    $("#results").append( "result: "+record["ID"] +"<br>");
    $("#results").append( "result: "+record["itemCode"] );
  });

})

I've also tried

    cSheetXref({"ID":{is:0}}).update({dbCol:ttitle});           

jsfiddle

added later The problem is that I'm passing a variable with the column name to the update command. If I use a constant, like this:

cSheetXref({"ID":0}).update({"itemCode":ttitle});

it works. Is is possible to pass a variable to the update command?

Upvotes: 0

Views: 233

Answers (1)

jidexl21
jidexl21

Reputation: 619

you already fixed the issue, from normal json knowledge, {dbCol:ttitle} is the same as {"dbCol":ttitle} which of course does not resolve to any column in your database. if you are looking to create a variable then use:

var item={}; 
var dbCol="itemCode";
var ttitle="example text";
item[dbCol] = ttitle; 
  cSheetXref({"ID":0}).update(item);

Upvotes: 1

Related Questions