小编Jam*_*ton的帖子

定义自定义Sublime Text 2片段的范围

在尝试为Sublime Text 2编写自己的代码片段时,我遇到了以下两个问题:

  1. 查找范围键.我发现我可以逐个查看我的包,并找到对声明的"范围"属性的引用.例如在~/Library/Application Support/Sublime Text 2/Packages/JavaScript/Comments.tmPreferences(我的HTML包中的文件)中有以下两行:

    <key>scope</key>
    <string>source.js</string>
    
    Run Code Online (Sandbox Code Playgroud)

    因此,如果我希望我的当前代码段能够处理javascript文件,我将我的范围定义为:

    <scope>source.js</scope>
    
    Run Code Online (Sandbox Code Playgroud)

    我假设所有这些范围键都是根据我安装的软件包即时定义的.Sublime Text是否在我可以更容易引用的任何地方构建列表?仔细阅读一堆包文件似乎过于繁琐.

  2. 定义多个范围属性.我已经想到了,以下行允许我的代码段在HTML和JavaScript文件中工作.

    <scope>text.html, source.js</scope>
    
    Run Code Online (Sandbox Code Playgroud)

scope code-snippets sublimetext2

64
推荐指数
5
解决办法
3万
查看次数

在构造函数内部分配原型方法* - 为什么不呢?

在风格上,我更喜欢这种结构:

var Filter = function( category, value ){
  this.category = category;
  this.value = value;

  // product is a JSON object
  Filter.prototype.checkProduct = function( product ){
    // run some checks
    return is_match;
  }

};
Run Code Online (Sandbox Code Playgroud)

对于这种结构:

var Filter = function( category, value ){
  this.category = category;
  this.value = value;
};// var Filter = function(){...}

Filter.prototype.checkProduct = function( product ){
  // run some checks
  return is_match;
}
Run Code Online (Sandbox Code Playgroud)

从功能上讲,以这种方式构造我的代码有什么缺点吗?将原型方法添加到构造函数体内的原型对象(即在构造函数的表达式语句关闭之前)会导致意外的范围问题吗?

我之前已经成功使用了第一个结构,但是我想确保自己没有为调试带来麻烦,或者由于编码错误导致开发人员悲痛和恶化.

javascript methods scope prototype

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

使用Shopify JavaScript Buy SDK自定义查询检索包含其图像的文章对象

我正在使用shopify-buy SDK尝试从我的Shopify商店中获取文章,只需使用前端的JavaScript,按照"扩展SDK"的说明进行操作:https://shopify.github.io/js-buy -sdk/#extended-the-sdk.

使用下面的代码,我能够检索我的文章和我需要的一些字段.

// Build a custom query using the unoptimized version of the SDK
const articlesQuery = client.graphQLClient.query((root) => {
  root.addConnection('articles', {args: {first: 10}}, (article) => {
    article.add('title')
    article.add('handle')
    article.add('url')
    article.add('contentHtml')
  })
})

// Call the send method with the custom query
client.graphQLClient.send(articlesQuery).then(({model, data}) => {
  console.log('articles data')
  console.log(data)
})
Run Code Online (Sandbox Code Playgroud)

但是,我真的需要为每篇文章提取特色图像,不幸的是,当我article.add('image')在articlesQuery中添加该行时,生成的文章数据日志null.我尝试构建自定义productsQuery,这有一个类似的问题 - 我可以检索一些产品字段,但是当我尝试添加该行时product.add('images'),我只是null从店面API返回.

有没有人有建立自定义/扩展查询和成功检索图像的经验?

javascript shopify shopify-javascript-buy-sdk

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

Python中Dictionary的替代方法 - 需要通过命名键引用值并按插入顺序迭代

我正在使用Python和Django,并将返回的JSON对象作为Python dictonaries,但我并不满足,因为我无法按插入顺序遍历我的字典元素.

如果我按如下方式创建字典:

measurements = {
  'units': 'imperial',
  'fit': request.POST[ 'fit' ],
  'height': request.POST[ 'height' ],
  'weight': request.POST[ 'weight' ],
  'neck': request.POST[ 'neck' ],
  # further elements omitted for brevity
}
Run Code Online (Sandbox Code Playgroud)

我可以尝试迭代它,如:

for k,v in measurements.iteritems():
  print k, 'corresponds to ', v
Run Code Online (Sandbox Code Playgroud)

结果是:

shoulders corresponds to  shoulders_val
weight corresponds to  weight_val
height corresponds to  height_val
wrist corresponds to  wrist_val
...
Run Code Online (Sandbox Code Playgroud)

我也尝试使用sorted(),按字母顺序按键遍历我的元素

bicep corresponds to  bicep_val
chest corresponds to  chest_val
fit corresponds to  fit_val
height corresponds to  height_val
...
Run Code Online (Sandbox Code Playgroud)

我是Python的新手.我希望找到某种方法来通过命名键来引用我的字典元素,例如测量['单位'],但仍然能够按照它们创建的顺序迭代这些元素.我知道有一个有序的字典模块 …

python dictionary loops

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

Wordpress get_transient()有时会返回编码字符串而不是数组

我一直在尝试制作一个自定义的推特小部件,它显示来自多个提要的最后几条推文.每个Feed都会创建以下类的实例:

<?php

class Foo{
  protected $name = '';

  //opts
  protected $numTweets = 3;
  protected $transName = ''; // Name of value in database.
  protected $backupName = '';
  protected $cacheTime = 5; // Time in minutes between updates.
  protected $exclude_replies = true; // Leave out @replies?

  public function __construct( $username ){
    $this->name = $username;
    $this->transName = 'jctft3' . $username;
    $this->backupName = 'jctfb3' . $username;
  }

  public function get_feed(){
    $feed = get_transient( $this->transName );

    // Do we already have saved tweet data? …
Run Code Online (Sandbox Code Playgroud)

wordpress plugins caching widget transient

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