我想从java脚本处理数组。 (即从html页面到插件代码,我希望从html代码中的值到插件中的变量,以便我可以在代码中修改它们并为其他目的进行处理)。npapi webkit插件数组处理
但我在此面临的一个问题。我知道内部一个数组将被作为NPObject处理。我试图从该NPObject检索数组的长度和数组的元素,但返回的数组长度为零,即使数组的长度不为零。
任何建议是欢迎....
我有具有阵列的HTML页面 HTML网页如下:
<html>
<script type="text/javascript">
var arrayData = [9,1,2,3,4,5,6,7,8,9];
function handleEvent(e) {
if (e.keyCode == 55) {
document.getElementById('arrayint_ele_disp').innerHTML = arrayData;
process_intarray(arrayData);
}
}
function process_intarray(arrayData){
obj = document.getElementById("Obj");
if(obj){
obj.process_array_intval(arrayData);
}
}
</script>
<body onload="init()" onkeydown="handleEvent(event)">
<div id ="arrayint_ele_disp" style="position:absolute;left:100px;top:250px">
ARRAY_INT VAL </div>
</body>
</html>
我的用于处理阵列元件插件代码是作为folows :
bool ScriptableObject::process_intarray(const NPVariant* args, uint32_t
argCount, NPVariant* result)
{
//Get the Length of the array
//NPObject *inobject = args[0].value.objectValue;
NPObject *inobject = args->value.objectValue;
bool bRetval = false;
NPVariant npvlength;
//NPIdentifier id;
bRetval =
NPN_GetProperty(m_npp,inobject,NPN_GetStringIdentifier("length"),&npvlength);
printf("\n NPN_GetProperty length type %d value : %d\n"
,npvlength.type,npvlength.value.intValue);
//Get the array elements
int i = 0;
for(i = 0; i < npvlength.value.intValue; i++)
{
NPVariant CurVal;
NPN_GetProperty(m_npp,inobject,NPN_GetIntIdentifier(i),&CurVal);
m_prop_array_intval[i] = CurVal.value.intValue;
}
return true;
}
在这里,在这个函数NPN_GetProperty(m_npp,inobject,NPN_GetStringIdentifier( “长度”),& npvlength);正在回归真实。
但在检查的npvlength其给予0和它作为NPVariantType_Double类型的长度。 我无法理解为什么..
任何建议,欢迎...
乔治您好,感谢的建议...我想npvlength.value.doubleValue还,但它仍然是零。和数组元素都是整数,所以我用npvlength.value.intValue ...任何其他建议... – Techtotie 2012-07-30 11:00:10
@ user1523492:只是可以肯定,你还可以调整你的'的printf()'语句中使用'%F '而不是'%d'? – 2012-07-30 11:02:45
嘿,我很抱歉它的工作原理...再次检查它....感谢:-) – Techtotie 2012-07-30 11:03:45