Click on http://groups.google.com/group/jnext/web/returning-array-to-javascript-layer
- or copy & paste it into your browser's address bar if that doesn't
work.
Hope this helps,
-Amnon
var f = new Array();
for (i=0;i<5;i++)
{
f[i] = new Socket()
}
But i want to do it from plugin layer. Only assign a function to an
Array.
I'm working with this problematic. Do you understand me?
Thanks
class Coordinate
{
public:
float x;
float y;
};
you can easily convert these 3 coordinates into a JavaScript code string
of (for example)
"var arCoords = [ [ 1.4, 4.3 ] , [ 2.0, 9.5 ] , [ 7.6, 2.2 ] ];"
then return this string to JavaScript and eval() it - you'll have all
your coordinate objects in the arCoords array. Of course this is just
one method of doing it, but it does the trick.
> I can do it, assign
> the n element of an array from javascript layer i.e:
>
> var f = new Array();
> for (i=0;i<5;i++)
> {
> f[i] = new Socket()
> }
>
> But i want to do it from plugin layer. Only assign a function to an
> Array.
>
> I'm working with this problematic. Do you understand me?
>
>
I'm not sure I understand. Could you give more information on what you
want to achieve ?
-Amnon
For example we have the next c++ object:
class Coordinate
{
public:
float x;
float y;
int add(int f,int t);
int div(int f,int t);
};
I want to return a Java Script Array containing Coordinate Elements,
and access methods from Java Script Layer.
for example
[Java Script Code]
var myArray = getObjectsArray() // This is a plugin function;
alert(myArray[0].add(5,5));
Do you undestand my problematic?
I understand your last reply, is the same that is develop on SQLLite
to return rows.
Thanks for your interest.
var objMyJNEXTClass = new MyJNEXTClass()
var myArray = objMyJNEXTClass.getObjectsArray();
alert(myArray[0].add(5,5));
after you define the following:
///////////////////////////////////////////////////////////////////
// Define the Coordinate class
///////////////////////////////////////////////////////////////////
function Coordinate( fX, fY )
{
var self = this;
self.fX = fX;
self.fY = fY;
self.add = function ( fX, fY )
{
// just an example - no real meaning
return self.fX + fX + self.fY + fY;
}
self.div = function ( fX, fY )
{
// just an example - no real meaning
return (self.fX + fX) / (self.fY + fY);
}
}
///////////////////////////////////////////////////////////////////
// Define the class that can return the coordinate array
///////////////////////////////////////////////////////////////////
function MyJNEXTClass()
{
var self = this;
self.getObjectsArray = function()
{
var strCoordVals = g_JNEXTDispatcher.invoke( self.m_strObjId,
"CoordsRequest", strPath );
var strEval = "arCoordVals = " + strCoordVals;
eval( strEval );
arCoords = self.CoordVals2CoordObjects( arCoordVals );
return arCoords;
}
// convert the data that was returned from the plugin to
JavaScript coordinate objects
self.CoordVals2CoordObjects = function( arCoordVals )
{
if ( arCoordVals == null )
{
return null;
}
arReply = new Array();
for (var i=0; i<arCoordVals.size; i++)
{
var coord = new Coordinate( fX, fY );
arReply.push( coord );
}
return arReply;
}
self.getId = function()
{
return self.m_strObjId;
}
self.init = function()
{
if ( !g_JNEXTDispatcher.require( "MyCoordinateLib" ) ) //
Defined in the C++ code
{
return false;
}
self.m_strObjId =
g_JNEXTDispatcher.createObject( "CoordinateArray" ); // Defined in the
C++ code
if ( self.m_strObjId == "" )
{
alert( "error initializing CoordinateArray" );
return false;
}
g_JNEXTDispatcher.registerEvents( self );
}
self.m_strObjId = "";
self.init();
}
///////////////////////////////////////////////////////////////////
I hope this helps,
-Amnon
All the best,
Amnon