小编mqu*_*lle的帖子

VSCode 扩展:内联 ES6 模板字符串的语言

我正在为 Visual Studio Code 开发一个 GraphQL 扩展,它实现了 GraphQL 架构和查询的语法突出显示和自动完成。它目前适用于以.gql扩展名结尾的文件。然而,一个常见的 GraphQL 用法是在 Javascript 文件中定义内联查询,例如:

@connect(gql`user(id: 2) { name, email }`)
function MyUIComponent({ user }) { ... }
Run Code Online (Sandbox Code Playgroud)

我如何支持我的扩展在 ES6(命名)模板字符串中实现的突出显示和自动完成功能?

visual-studio-code vscode-extensions

5
推荐指数
1
解决办法
832
查看次数

Python中的格式语法

有没有办法以更好的方式编写这行代码:

"""{a};{b};{c};{d}""".format(a = myDictionary[a], b = myDictionary[b], c = myDictionary[c], d = myDictionary[d])
Run Code Online (Sandbox Code Playgroud)

这样的事情?

"""{a};{b};{c};{d}""".format(myDictionary)
Run Code Online (Sandbox Code Playgroud)

python format syntax

3
推荐指数
1
解决办法
579
查看次数

Meteor - 客户端和服务器中的Account.createUser

我理解在客户端和服务器中都有业务逻辑的原因,但我不清楚在某些情况下如何做到这一点.这里举例如下:

// client/client.js
// hnadling click event on the Create Accounts button
Template.homecontent.events({
  'click #btnCreateAccount': function (event, template) {
    var userEmail = template.find('#email').value,
      userName  = template.find('#newusername').value,
      password  = template.find('#newpassword').value,
      password2 = template.find('#password2').value,
      name      = template.find('#fullname').value;

    validates = true;
   //do some validation here
   if(password != password2) {
      validates = false;
   }

    if(validates === true) {
      Accounts.createUser({
        username: userName,
        email:    userEmail,
        password: password,
        profile: {
          name: name
        }
      }, function (error) {
        if (error) {
          console.log("Cannot create user");
        }
      });
    }
  } …
Run Code Online (Sandbox Code Playgroud)

validation meteor

3
推荐指数
3
解决办法
9838
查看次数

为什么python不包含有序的dict(默认情况下)?

Python有一些很好的结构来建模数据.这里有一些 :

              +-------------------+-----------------------------------+
              | indexed by int    | no-indexed by int                 |
+-------------+-------------------+-----------------------------------+
| no-indexed  | [1, 2, 3]         | {1, 2, 3}                         |
| by key      | or                | or                                |
|             | [x+1 in range(3)] | {x+1 in range(3)}                 |
+-------------+-------------------+-----------------------------------+
| indexed     |                   | {'a': 97, 'c': 99, 'b': 98}       |
| by key      |                   | or                                |
|             |                   | {chr(x):x for x in range(97,100)} |
+-------------+-------------------+-----------------------------------+
Run Code Online (Sandbox Code Playgroud)

为什么python默认不包含由key + int索引的结构(如PHP数组)?我知道有一个模拟这个对象的库(http://docs.python.org/3/library/collections.html#ordereddict-objects).但这里是从文档中获取的"orderedDict"的表示:

OrderedDict([('pear', 1), ('apple', 4), …
Run Code Online (Sandbox Code Playgroud)

python

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