PDA

View Full Version : if = missing : after property id



MacJK
23 Jul 2009, 7:14 AM
Hello, i understand this measage, but how i can make a IF in the params: property?


function saveRecord(oGrid_event){
Ext.Ajax.request({
waitMsg: 'Please wait...',
url: 'database.asp',
params: {
if (oGrid_event.record.data.task == "create")
{task: 'create';},
else
{task: 'update';},
ObjectOrder: oGrid_event.record.data.ObjectOrder,
ObjectTypeID: oGrid_event.record.data.ObjectTypeID,
Name: oGrid_event.record.data.Name
},
success: function(response){
var result=eval(response.responseText);
switch(result){
case 1:
store.commitChanges();
store.reload();
break;
default:
Ext.MessageBox.alert('Uh uh...','We couldn\'t save him...');
break;}
},
failure: function(response){
var result=response.responseText;
Ext.MessageBox.alert('error','could not connect to the database. retry later');}
});
};

i get alwas a erro like this:

missing : after property id

function(){\n

Many thanks for all help!

best regards
Jaroslaw

fanzhongkai
23 Jul 2009, 7:53 AM
if (oGrid_event.record.data.task == "create")
{task: 'create';},
else
{task: 'update';},


try this:


task: oGrid_event.record.data.task == "create"?"create":"update",
....


You can not add if ... else ... as the params' property!

tryanDLS
23 Jul 2009, 7:55 AM
This is not an Ext issue - it's JavaScript. You can't use an if inside an object declaration. You could do


params :{
task: oGrid_event.record.data.task == "create" ? "create" : "update"}
}

MacJK
23 Jul 2009, 9:15 AM
Hello fanzhongkai and tryanDLS,

many thanks for fast reply both. I understand that this is no a ExtJS issue. This help me to use this powerfull and great Extension. I still testing but very impressiv. Many thanks again!

My code now:


params: {
task: oGrid_event.record.data.task == "create" ? "create" : "update",
ObjectOrder: oGrid_event.record.data.ObjectOrder,
ObjectTypeID: oGrid_event.record.data.ObjectTypeID,
Name: oGrid_event.record.data.Name
},

br
Jaroslaw Kucharski