小编Igo*_*uan的帖子

节点js.续集交易

我的数据库中有'Banks'表和'money'字段,

用户可以定期提款,但只有在银行存款> 0时才可以提款.

首先我应该获得银行的实体,然后检查是否(bank.money> amountToWithdraw)然后撤回这个金额.

想象一下这种情况,当并发用户试图提取一些钱时.在那一刻,当我检查(bank.money> amountToWithdraw)其他用户是否可以执行提款操作时,DB中的实际bank.money金额将会减少.

如何申请交易查找银行业务(如何锁定银行实体)?

models.sequelize.transaction(function (t) {

return models.Banks.findOne({where: {
    money: {
      $gt: 0
    }
  }).then(function(bank){

    //in this moment other user finished the same operation
// how to lock access for editing bank object by other users after //findOne method?

    bank.money -= amountToWithdraw;
    return bank.save({transaction: t});
  })
})
Run Code Online (Sandbox Code Playgroud)

javascript transactions node.js sequelize.js

10
推荐指数
1
解决办法
1万
查看次数

iOS版.尝试在UIViewController上呈现UIAlertController,其视图不在窗口层次结构中

Swift 3,Xcode 8.1.我想显示UIAlertControllerUIViewController.

我有方法:

private static func rootViewController() -> UIViewController {
    // cheating, I know

    return UIApplication.shared.keyWindow!.rootViewController!
}

static func presentAlert(_ message: String) {
    let alertView = UIAlertController(title: "RxExample", message: message, preferredStyle: .alert)
    alertView.addAction(UIAlertAction(title: "OK", style: .cancel) { _ in })

    rootViewController().present(alertView, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)

您可以在此处找到此课程的完整代码

我将方法presentAlert称为viewDidLoad:

override func viewDidLoad() {
    super.viewDidLoad()
    DefaultWireframe.presentAlert("test")
    ...
}
Run Code Online (Sandbox Code Playgroud)

并得到警告:

警告:尝试在UIViewController上显示UIAlertController:0x7f904ac0d930:0x7f904ad08040,其视图不在窗口层次结构中!

如何避免警告并显示警报?

它在我尝试在初始ViewController中显示Alert时有效,但它在使用push segue与初始VC连接的另一个ViewController中不起作用.

uiviewcontroller ios swift

9
推荐指数
1
解决办法
1万
查看次数

斯威夫特用户界面。如何为 Spacer 设置收缩行为?

如果容器 (VStack) 与底部黑色视图不冲突,如何设置 rgb 视图 (100pt) 之间的默认间距。(如 iPhone 11 Pro Max)。如果没有 100p 高度的空间,则会缩小。(如屏幕截图中的 iPhone SE)

我的代码:

struct ContentView: View {
    var body: some View {
        VStack(spacing: 0) {
            VStack(spacing: 0) {
                Rectangle()
                    .foregroundColor(.red)
                    .frame(height: 100)
                Spacer()
                    .frame(minHeight: 10, maxHeight: 100)
                Rectangle()
                    .foregroundColor(.green)
                    .frame(height: 100)
                Spacer()
                    .frame(minHeight: 10, maxHeight: 100)
                Rectangle()
                    .foregroundColor(.blue)
                    .frame(height: 100)
            }
            Spacer()
                .frame(minHeight: 10, maxHeight: 600)
            Rectangle() // keyboard
                .frame(height: 200)
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

所以问题是: 在 iPhone 11 Pro Max 上,具有 maxHeight: 100 的垫片的高度 = …

layout constraints ios swift swiftui

9
推荐指数
2
解决办法
1736
查看次数

RxSwift.CombineLatest.并非所有可观测量都被发射出去

Observable.combineLatest(...){...}包含几个可观察对象,但是没有发出一些这些可观察对象.

只有在发出此方法中的所有可观察对象时,combineLatest才会发出.

如何跳过不发出的observable并发出combineLatest?

let tap = firstButton.rx.tap.asObservable().map{ (_) -> Observable<Item> ...}

let textfieldObservable = viewTextField.rx.text.orEmpty.asObservable()

submitButton.rx.tap.withLatestFrom(Observable.combineLatest(textfieldObservable, tap ... )).flatMapLatest({
...
// this method will not be executed without tap on firstButton before tapping on submitButton

}
)
Run Code Online (Sandbox Code Playgroud)

ios swift rx-swift rx-cocoa

2
推荐指数
1
解决办法
2791
查看次数