我想從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