小编kan*_*nix的帖子

chai测试数组相等不能按预期工作

为什么以下失败?

expect([0,0]).to.equal([0,0]);
Run Code Online (Sandbox Code Playgroud)

什么是测试的正确方法?

mocha.js node.js chai

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

knockout将键值对象绑定到下拉列表

我有以下型号:

var allCategories = [{
    id: 1,
    name: 'Red'},
{
    id: 5,
    name: 'Blue'}];

function model() {
    self = this;
    self.name = ko.observable("");
    self.categoryId = ko.observable(-1);
    self.categoryName = ko.computed(function() {
        if (self.categoryId() == -1) return "";
        return getCategoryNameById(self.categoryId()).name;
    });
}

function getCategoryNameById(id) {
    return _.find(allCategories, function(cat) {
        return cat.id == id;
    });
}
Run Code Online (Sandbox Code Playgroud)

我想提供一个下拉列表来选择类别,但我不知道如何绑定它.也许我对我的模型使用了错误的方法,但这很可能是我如何从服务器获取数据,所以我试图将我的JS包装起来.

我试过这样的事情:

<select data-bind="options: categories, optionsText: 'name', value: 'id', optionsCaption: 'Categorie...'"></select>
Run Code Online (Sandbox Code Playgroud)

但我不知道如何将下拉值连接到模型categoryId.

这是一个关于name属性的工作绑定的小提琴.

knockout.js

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

iOS 7.1中的safari全屏,带有minimal-ui元标记

我已经阅读了多个站点(包括一些stackoverflow问题),iOS 7.1 Safari将有一个最小的ui元标记.所以今天我更新了我的iPad,似乎没有效果.任何人都可以确认这应该有效吗?

这是我的元标记:

<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no, minimal-ui">
Run Code Online (Sandbox Code Playgroud)

safari mobile-safari ios7 safari-minimal-ui

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

jQuery处理/隐藏预期的Ajax 404错误

我使用ajax head请求来检查文件.在大多数情况下,该文件将不存在,以某种方式阻止404显示在我的调试控制台中会很好.有没有一个很好的方法来实现这一目标?

需要明确的是:http://jsfiddle.net/kannix/FFLdP/

jquery

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

Rails嵌套路由+浅编辑无法正常工作

我想使用这样的路由:

resources :customers do
  resources :electricity_counters, :shallow => true do
    resources :electricity_bills, :shallow => true
  end
end
Run Code Online (Sandbox Code Playgroud)

创建electric_counter工作正常,但编辑不能按预期工作..如果我访问electricity_counters/1 /编辑我只会得到空白字段,我的所有数据都丢失了.

我的_form.html.erb就是这样开始的

<%= form_for([@customer, @customer.electricity_counters.build]) do |f| %>
Run Code Online (Sandbox Code Playgroud)

新的和编辑的控制器方法是这样的:

# GET customers/1/electricity_counters/new
  def new
    @customer = Customer.find(params[:customer_id])
    @electricity_counter = @customer.electricity_counters.build
  end

  # GET /electricity_counters/1/edit
  def edit
    @electricity_counter = ElectricityCounter.find(params[:id])
    @customer = @electricity_counter.customer
  end
Run Code Online (Sandbox Code Playgroud)

在调试中似乎是我的@customer变量没有设置正确..但也许我只是愚蠢使用该aptana调试器;)

electric_counter模型与客户的关联设置为:

belongs_to :customer
Run Code Online (Sandbox Code Playgroud)

那么我做错了什么?

ruby-on-rails

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

angularjs验证输入并防止更改(如果无效)

我需要一个输入字段,我只能输入值1,2或3,因此我正在尝试构建一个指令,如果它与这些值不匹配,则会阻止对模型的所有更改.
例如,值为1,我将其更改为5,它应该仍为1.

我把一个小小提琴http://jsfiddle.net/kannix/Q5YKE/放在一起但是使用$解析器很可能是错误的.

app.directive('myvalidator', function () {
    return {
        require: 'ngModel',
        link: function (scope, elm, attrs, ctrl) {
            var validValues = [1,2,3];
            ctrl.$parsers.push(function (value) {
                if (validValues.indexOf(value) === -1){
                    //what to do here? should refuse wrong value and leave the old one
                }   
            });
        }
    }   

})
Run Code Online (Sandbox Code Playgroud)

javascript angularjs angularjs-directive

4
推荐指数
2
解决办法
2万
查看次数

gcloud部署错误:找不到标记为google/docker-registry的图片

我正在尝试使用此命令部署此项目https://github.com/GoogleCloudPlatform/appengine-nodejs-quickstart

gcloud --project poised-graph-758 preview app deploy --server preview.appengine.google.com .
Run Code Online (Sandbox Code Playgroud)

但我得到这个错误:

Updating module [default] from file [/Users/kannix/Desktop/tmp/appengine-nodejs-quickstart/app.yaml]
11:36 PM Host: preview.appengine.google.com
{bucket: vm-containers.poised-graph-758.appspot.com, path: /containers}

Traceback (most recent call last):
  File "/Users/kannix/google-cloud-sdk/./lib/googlecloudsdk/gcloud/gcloud.py", line 153, in <module>
    main()
  File "/Users/kannix/google-cloud-sdk/./lib/googlecloudsdk/gcloud/gcloud.py", line 149, in main
    _cli.Execute()
  File "/Users/kannix/google-cloud-sdk/./lib/googlecloudsdk/calliope/cli.py", line 381, in Execute
    post_run_hooks=self.__post_run_hooks, kwargs=kwargs)
  File "/Users/kannix/google-cloud-sdk/./lib/googlecloudsdk/calliope/frontend.py", line 274, in _Execute
    pre_run_hooks=pre_run_hooks, post_run_hooks=post_run_hooks)
  File "/Users/kannix/google-cloud-sdk/./lib/googlecloudsdk/calliope/backend.py", line 887, in Run
    result = command_instance.Run(args)
  File "/Users/kannix/google-cloud-sdk/./lib/googlecloudsdk/calliope/exceptions.py", line 78, in TryFunc
    return func(*args, **kwargs)
  File …
Run Code Online (Sandbox Code Playgroud)

google-app-engine

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

LitElement 加载外部脚本

我尝试简单地将其加载到渲染的 HTML 中,但这不起作用。

当前代码:

render() {
    return html `<script @onload="${this.mapKitLoadedCallback}" src="https://cdn.apple-mapkit.com/mk/5.x.x/mapkit.js"></script>`;
}
Run Code Online (Sandbox Code Playgroud)

web-component polymer-3.x lit-element

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

Camera.Parameters设备特定崩溃(三星S3 Mini)

以下代码正在使用Galaxy Nexus,三星S3和HTC One X,但它在三星S3 Mini上崩溃

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    Log.d(TAG, "entering surfaceChanged");
    Camera.Parameters parameters = camera.getParameters();
    List<Camera.Size> previewSizes = parameters.getSupportedPreviewSizes();

    // set barcode scene mode
    if (parameters.getSupportedSceneModes() != null && parameters.getSupportedSceneModes().contains(Camera.Parameters.SCENE_MODE_BARCODE)){
        parameters.setSceneMode(Camera.Parameters.SCENE_MODE_BARCODE);
        Log.d(TAG, "setting parameters.setSceneMode(Camera.Parameters.SCENE_MODE_BARCODE)");
    }


    Camera.Size size = previewSizes.get(0);
    if (previewSizes.size() > 2)
        size = previewSizes.get(2);
    else if (previewSizes.size() > 1)
        size = previewSizes.get(1);

    parameters.setPreviewSize(size.width, size.height);
    Log.d(TAG, "picsize w: " + Integer.toString(size.width) + " h: " + Integer.toString(size.height));
    if (Build.VERSION.SDK_INT > …
Run Code Online (Sandbox Code Playgroud)

java android android-camera android-camera-intent samsung-mobile

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

angularjs将服务数组长度属性绑定到控制器范围

我正在尝试将数组长度从其他服务绑定到我的控制器范围,如下所示:

app.controller('TestCtrl', function ($scope, safePostService) {
    $scope.count = safePostService.queue.length;

    $scope.addOne = function () {
        safePostService.post('/echo/json/', {
            json: JSON.stringify({
                text: 'some text',
                array: [1, 2, 'three'],
                object: {
                    par1: 'another text',
                    par2: [3, 2, 'one'],
                    par3: {}
                }
            }),
            delay: 3
        });
    };
});
Run Code Online (Sandbox Code Playgroud)

那是我的服务:

app.service('safePostService', function ($http, $timeout) {
    var self = this;

    var syncIntervall = 1000;
    var timeoutPromise;
    var sending = false;

    this.queue = [];

    this.post = function (url, data) {
        self.queue.push({
            url: url,
            data: data
        });
        syncNow();
    }; …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs

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

在隐藏的 html5 画布元素中绘制不起作用

我试图在画布中绘制,而其父级是display:none. 有没有办法做到这一点?

这是一个 jsFiddle 来演示我的问题:http : //jsfiddle.net/kannix/jSj83/

如果您只是单击绘图,一切都会按预期进行。如果您单击“显示/隐藏”并在隐藏时单击“绘制”按钮,单击“显示/隐藏”将显示画布,但它仍然是空的。

html canvas html5-canvas

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

使用所有分支恢复 gitlab 备份存储库捆绑文件

我需要从 gitlab 备份中恢复一些存储库。此备份包含所有存储库的 .bundle 文件。如何恢复包含所有分支的完整存储库?

如果我跑,git bundle list-heads myfile.bundle我可以看到所有的分支。

我想使用所有分支在本地恢复该 repo,以将其推送到新的/空的 gitlab 存储库。

我尝试使用 git clone、git pull 我能找到的所有其他技巧,但这只会导致一个只有 master 分支的 repo。

git gitlab git-bundle

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