我有一个 web 组件x-counter,它在一个文件中。
const template = document.createElement('template');
template.innerHTML = `
<style>
button, p {
display: inline-block;
}
</style>
<button aria-label="decrement">-</button>
<p>0</p>
<button aria-label="increment">+</button>
`;
class XCounter extends HTMLElement {
set value(value) {
this._value = value;
this.valueElement.innerText = this._value;
}
get value() {
return this._value;
}
constructor() {
super();
this._value = 0;
this.root = this.attachShadow({ mode: 'open' });
this.root.appendChild(template.content.cloneNode(true));
this.valueElement = this.root.querySelector('p');
this.incrementButton = this.root.querySelectorAll('button')[1];
this.decrementButton = this.root.querySelectorAll('button')[0];
this.incrementButton
.addEventListener('click', (e) => this.value++);
this.decrementButton
.addEventListener('click', (e) => this.value--);
} …Run Code Online (Sandbox Code Playgroud) html javascript templates separation-of-concerns web-component
我可以通过 Swagger文章使用带有自动生成的 OpenAPI 文档的Express API配置 swagger url 。
我正在使用 TypeScript,它.js在 dist 下生成没有添加任何 API 文档注释的文件。指向apis: ['../dist/*.js']或指向Route.ts生成 API 详细信息。我没有使用任何休息装饰器。
/**
* @swagger
* /:
* get:
* description: This should return ok
*/
this.router.get("/", (req: Request, res: Response) => this.api.process(req, res));
Run Code Online (Sandbox Code Playgroud)
该Routes.tsAPI文档看起来就像上面。如何从中生成swagger doc?
我有以下nodejs程序
import readline from 'readline'
readline.createInterface({input: process.stdin, output: process.stdout}).prompt()
process.stdin.on('keypress', (letter, key) => console.log({letter: letter, key: key}))
Run Code Online (Sandbox Code Playgroud)
这在大多数情况下都有效,例如如果我按SHIFT+X,它会正确输出key.shift === True:
{
letter: 'X',
key: { sequence: 'X', name: 'x', ctrl: false, meta: false, shift: true }
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我按SHIFT+ENTER,则key.shift永远不会true:
{
letter: '\r',
key: {sequence: '\r', name: 'return', ctrl: false, meta: false, shift: false}
}
Run Code Online (Sandbox Code Playgroud)
为什么?如何检测在 Node.js 中的SHIFT+ENTER使用readline?
我想做什么?我正在构建一个终端提示应用程序,因此该readline模块非常方便,因为它带有自动完成器、历史记录、分页、提示前缀等。但是,我也希望能够输入多行提示。
在 Swift 中structs是值类型。如果我有一个包含大量数据的结构(假设)并且我将该结构传递给许多不同的函数,那么每次都会复制该结构吗?如果我同时调用它,那么内存消耗会很高,对吗?
我正在尝试向我创建并添加以编程方式查看的表视图添加约束。我想根据 a 来约束它,UITextField这是一个IBOutlet. 但是,我收到以下错误:
*** 由于未捕获的异常“NSGenericException”而终止应用程序,原因:“无法激活带有锚点的约束,因为它们没有共同的祖先。约束或其锚点是否引用不同视图层次结构中的项目?这是非法的。
@IBOutlet weak var authorTextField: UITextField!
override func viewDidLoad() {
myTableView = MyTableView(frame: CGRect(x: 0, y: 80, width: 320, height: 120), style: .plain)
myTableView!.isHidden = false
myTableView!.backgroundColor = UIColor.green
self.view.addSubview(myTableView!)
myTableView.setConstraints(to: authorTextField) // <-- this fails
Run Code Online (Sandbox Code Playgroud)
// MyTableView.swift ..
func setConstraints(to view: UIView)
self.translatesAutoresizingMaskIntoConstraints = false
self.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 8.0).isActive = true
self.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -8.0).isActive = true
}
Run Code Online (Sandbox Code Playgroud)
如何添加这个约束呢?
我有一个带有列表的水平滚动视图。水平滚动时,如何使列表对齐边缘。
struct RowView: View {
var post: Post
var body: some View {
GeometryReader { geometry in
VStack {
Text(self.post.title)
Text(self.post.description)
}.frame(width: geometry.size.width, height: 200)
//.border(Color(#colorLiteral(red: 0.1764705926, green: 0.01176470611, blue: 0.5607843399, alpha: 1)))
.background(Color(#colorLiteral(red: 0.721568644, green: 0.8862745166, blue: 0.5921568871, alpha: 1)))
.cornerRadius(10, antialiased: true)
.padding(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
}
}
}
struct ListView: View {
var n: Int
@State var posts = [Post(id: UUID(), title: "1", description: "11"),
Post(id: UUID(), title: "2", description: "22"),
Post(id: UUID(), …Run Code Online (Sandbox Code Playgroud) 我正在将iOS Firebase SDK与Google登录集成。当用户点击GIDSignIn按钮时,该应用会显示一条警报,显示"MyAPP" want to use Google.com for Sign in,但该警报很快就会消失。我在didSignInFor user: GIDGoogleUser方法中得到的错误如下:
2019-02-21 16:54:13.104279+0530 MyApp[18743:185089] [Warning] Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior (<SFAuthenticationViewController: 0x7fa327945800>)
[DEBUG] Google sign-in error: Error Domain=com.google.GIDSignIn Code=-5 "The user canceled the sign-in flow." UserInfo={NSLocalizedDescription=The user canceled the sign-in flow.}
Run Code Online (Sandbox Code Playgroud)
我已遵循iOS文档上的“使用Google登录进行身份验证”。
我还尝试在iOS 9上的Google登录崩溃时尝试回答该问题,尝试调用canOpenURL,但它不起作用。
该AppDelegate …
我已经添加并导入了AudioToolbox框架。但我的项目无法看到该文件AudioDeviceID,AudioObjectPropertyAddress. 它给出了错误,Use of undeclared type 'AudioDeviceID'. 我尝试了一个示例核心音频项目,它工作得很好。我错过了什么吗?
我想动态地将孩子添加到simple_one_for_one主管中。为此,我正在考虑使用make_ref()ref 创建子标识符并将其保存在地图中。孩子终止后,该参考将从地图中删除。在这种情况下,将通过垃圾收集引用吗?
在Core Audio Recorder 示例中,该AudioQueueInputCallback函数被编写为类之外的变量绑定Recorder。我试图在结构中使用它,但我无法访问任何实例方法。它给出了错误,实例成员不能用于类型。
struct Recorder {
private var log = Logger()
private let utils = Utils()
func record() {
// ...
AudioQueueNewInput(&recordFormat, audioQueueInputCallback, &recorder, nil, nil, 0, &queue)
}
private let audioQueueInputCallback: AudioQueueInputCallback = { (inUserData: UnsafeMutableRawPointer?, inQueue: AudioQueueRef,
inBuffer: AudioQueueBufferRef, inStartTime: UnsafePointer<AudioTimeStamp>,
inNumPackets: UInt32, inPacketDesc: UnsafePointer<AudioStreamPacketDescription>?) in
log.debug() // <-- error: instance member cannot be used on type Recorder
}
Run Code Online (Sandbox Code Playgroud)
如何audioQueueInputCallback在结构内部写入以便可以在其中访问实例变量?
更新:如果我将 var 更改为 lazy 为:
private lazy …Run Code Online (Sandbox Code Playgroud) 我想在 JavaScript 中向 string 添加一个 count 属性,该属性在内部调用 length 属性。我不想将其添加为函数。这该怎么做?
"abc".count; // 3
Run Code Online (Sandbox Code Playgroud) 我正在使用 vaadin select 来显示带有状态的选择菜单。
private Select<States> states = new Select<>();
Run Code Online (Sandbox Code Playgroud)
states.setLabel("State");
states.setItems(facade.stateService().findAllStates());
states.setItemLabelGenerator(States::getName);
Run Code Online (Sandbox Code Playgroud)
Optional<States> state = facade.stateService().findByCode(location.getLocationState());
if (state.isPresent()) {
states.setValue(state.get()); // this is not working
}
Run Code Online (Sandbox Code Playgroud)
我正在获取状态值并使用它进行设置,states.setValue()但选择不显示更新的状态。该方法正在被调用。如何使选择的菜单被选中?谢谢。