【问题标题】:How to observer path change in dialog如何在对话框中观察路径变化
【发布时间】:2016-05-18 09:54:24
【问题描述】:

在我的电子应用程序中, 我想通过对话框缓存文件路径更改,

Polymer({
is:'myelement',
properties:{
  path:{
        type:String,
        defaultValue:'test',
        observer:'_pathChanged'
        }
}   
        _pathChanged: function(newalue,oldvalue){
        alert('new:' + newvalue + 'oldvalue' + oldvalue)
        }
})

关于对话框

           showDialog:function(){
             var remote = require('remote')
             var dialog = remote.require('dialog')
             dialog.showOpenDialog({properties:['openDirectory'],
             function(dirPath){
             if (dirPath){
             this.path=dirPath
             }
           }
          }

但是,当在对话框中选择不同的文件时,观察者不起作用。

【问题讨论】:

标签: javascript dialog polymer polymer-1.0 electron


【解决方案1】:

您的代码存在几个问题,首先,您需要在传递给dialog.showOpenDialog() 的回调函数中将this 绑定到您的元素实例。其次,dirPath 实际上是一个数组。因此,这是解决这些问题的一种方法:

dialog.showOpenDialog(
  null, { properties:['openDirectory'] },
  dirPaths => {
    if (dirPaths && dirPaths.length){
      this.path = dirPaths[0];
    }
  }
)

【讨论】:

    猜你喜欢
    • 2013-01-23
    • 1970-01-01
    • 2011-03-25
    • 2018-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-07
    • 2019-03-23
    相关资源
    最近更新 更多