Monday, March 31, 2008

javascript array comparison


var master = new Array("11", "12", "13", "14", "15","16","17","18","19");
var all = new Array("11", "12", "13", "14", "15","16","17","18","19");
var has_app = new Array("11","12","16", "17", "19");
// expected out put = 13,14,15,18
var exp = "13,14,15,18";
var count = 0;
function compareAndRemove(){
outer :for(var i=0; i(is less than)master.length; i++){
inner :for(var j=0; j(is less than)has_app.length; j++){
if(master[i] == has_app[j]){
count = i - j;
all.splice(count,1);
}
}
}
alert(" All:"+all+" exp :"+exp);
}

Thursday, March 20, 2008

OS:Passing data to apps and navigation

Passing data to your application through requestNavigateTo()

If you are using the opensocial.requestNavigateTo() calls, you may supply an optional parameter containing data to be passed to the new page.

The following code passes two variables: foo and bar to the canvas surface of the current application:

  function gotoCanvas(params) {
var canvas_surface = new opensocial.Surface("canvas");
opensocial.requestNavigateTo(canvas_surface, params);
};

var my_params = {
foo : 12345,
bar : "Bar value"
};

gotoCanvas(my_params);

In the canvas view, check for these values with the following code:

  var prefs = opensocial.getEnvironment().getParams();
var foo = prefs["foo"];
/* foo contains 12345 */

var bar = prefs["bar"];
/* bar contains "Bar value" */

You should see that after the navigation has taken place, your URL will look similar to:

http://sandbox.orkut.com/Application.aspx?appId=xxxxxx&uid=xxxxxx&appParams=foo%3D12345%26bar%3DBar%20value

This follows the same format as discussed in Passing data to your application through the querystring