English 中文(简体)
派遣人员和联系阵列
原标题:dispatchMessage and associative arrays

我有一个问题,即向注射文字提供可观阵列。

Global.html

  var settings = new Array();

  settings["accountID"] = safari.extension.settings.getItem("accountID");
  settings["accountName"] = safari.extension.settings.getItem("accountName");
  settings["accountEmail"] = safari.extension.settings.getItem("accountEmail");

            safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("settingsArray", settings);

js

 switch (msgEvent.name) {
      case "settingsArray":
           var settings = new Array();
           settings = msgEvent.message;
           console.log("accountID: " + settings["accountID"]);

           break;

www.un.org/Depts/DGACM/index_spanish.htm 当我用“热”阵列做时,它会做精细!

但是,在提供联系阵列时,我总是在打电话时获得“un defined>。

是否有任何人认为什么错误?

最佳回答
  1. 当你使用物体时,请重新使用阵列。

    var settings = new Array();  // Wrong
    var settings = {};           // Right (and better than "new Object()")
    
  2. 你们不必要地利用财产获取的严格形式。

    settings["accountID"] = …;   // Works, but too much typing
    settings.accountID = …;      // Exact same functionality
    

    如果财产名称不是有效的 Java本标识,你在获得/确定财产价值时只需要使用彩票(例如foo[”holy!*#$! 或者,如果你需要从变数(例如<代码>foo[“账户”+n] = “活性”;

  3. 你们正在制造新的物体,然后将其 throw弃。

     var settings = new Array();  // Makes a new array referenced by a variable
     settings = msgEvent.message; // Discards the array and changes the variable
                                  // to reference a new object
    
问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.