为什么启用面板代码时,addone按钮会丢失? [英] Why the addone button is lost when I enable panel code?

查看:175
本文介绍了为什么启用面板代码时,addone按钮会丢失?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一旦 require(sdk / panel)。Panel 代码被启用,我找不到addone按钮,甚至在自定义页面中找不到它,怎么了?



  var buttons = require('sdk / ui / button / action'); 
var tabs = require(sdk / tabs);
var data = require(sdk / panel)。data;

// var okentry = require(sdk / panel)。Panel({
// contentURL:data.url(okentry.html),
// contentScriptFile:data.url(okentry.js)
//});

var button = buttons.ActionButton({
id:test-panel,
label:ok,
icon:{
16:./icon-16.png,
32:./icon-32.png,
64:./icon-64.png
},
onClick:handleClick
});

函数handleClick(状态){
tabs.open(https://www.baidu.com/);
// okentry.show();
alert('hi');
console.info(tabs.length);


解决方案

原因是这一行:

  var data = require(sdk / panel)。data; 

但您应该写:

<$ p $ data> require(sdk / self)。data;

作为require(sdk / panel)没有data,变量变成undefined。后来,当你调用data.url(okentry.html)时,浏览器会抛出异常和Panel构造函数,下面的所有代码都不会被执行。


Once the require("sdk/panel").Panel code is enabled, I cannot find the addone button, even cannot find it in customize page, what's wrong?

var buttons = require('sdk/ui/button/action');
var tabs = require("sdk/tabs");
var data = require("sdk/panel").data;

// var okentry=require("sdk/panel").Panel({
//   contentURL: data.url("okentry.html"),
//   contentScriptFile: data.url("okentry.js")
// });

var button = buttons.ActionButton({
  id: "test-panel",
  label: "ok",
  icon: {
    "16": "./icon-16.png",
    "32": "./icon-32.png",
    "64": "./icon-64.png"
  },
  onClick: handleClick
});

function handleClick(state) {
  tabs.open("https://www.baidu.com/");
  // okentry.show();
  alert('hi');
  console.info(tabs.length);
}

解决方案

The reason is this line :

var data = require("sdk/panel").data;

but you should write :

data = require("sdk/self").data;

as require("sdk/panel") has no "data", the variable became undefined. Later, when you call data.url("okentry.html"), browser throws exception and Panel constructor and all code below is not executed.

这篇关于为什么启用面板代码时,addone按钮会丢失?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆