小编Yos*_*ero的帖子

使用AngularJS中的Promises成功/错误/ finally/catch

$http在AngularJs中使用,我不确定如何使用返回的promise并处理错误.

我有这个代码:

$http
    .get(url)
    .success(function(data) {
        // Handle data
    })
    .error(function(data, status) {
        // Handle HTTP error
    })
    .finally(function() {
        // Execute logic independent of success/error
    })
    .catch(function(error) {
        // Catch and handle exceptions from success/error/finally functions
    });
Run Code Online (Sandbox Code Playgroud)

这是一个很好的方法吗,还是有更简单的方法?

promise angularjs angularjs-http

111
推荐指数
5
解决办法
19万
查看次数

如何修改字符串过滤器中输入的值

我的网格中有3列的字符串过滤器.这工作正常.在第三列,其dataindex是abc我想修改输入的值.

例如,如果我按0然后它过滤了所有具有0的数据.我想按'否'而不是0来过滤.同样,我想使用"是"而不是1来过滤数据1.

我的代码用于创建过滤器.

this.filters = new Ext.ux.grid.GridFilters({
    filters: this.filter,
    local: true,
    autoReload: false,
});
this.features = [this.filters];
this.plugins = [this.filters];
Run Code Online (Sandbox Code Playgroud)

插入过滤器的代码.

gridEl.filter.push({
    type: header.getAttribute("FILTER"),
    dataIndex: header.getAttribute("DATAINDEX"),
    encode: false,
    metaID: header.getAttribute("M"),
});
Run Code Online (Sandbox Code Playgroud)

感谢帮助.

javascript string extjs filter extjs3

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

如何使用javascript过滤复杂的json对象?

我有以下json对象:

var json = {
    "Lofts": "none",
    "Maisons": "2",
    "HOMES": [{
        "home_id": "1",
        "price": "925",
        "num_of_beds": "2"
    }, {
        "home_id": "2",
        "price": "1425",
        "num_of_beds": "4",
    }, {
        "home_id": "3",
        "price": "333",
        "num_of_beds": "5",
    }]
};
Run Code Online (Sandbox Code Playgroud)

如何过滤此对象并保留在home_id = 2的HOMES属性中?

结果:

var json = {
    "Lofts": "none",
    "Maisons": "2",
    "HOMES": [{
        "home_id": "2",
        "price": "1425",
        "num_of_beds": "4",
    }]
};
Run Code Online (Sandbox Code Playgroud)

有什么方法可以循环对象和mantein所有的属性(也是阁楼和maisons)?

谢谢

javascript jquery json filter

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

为什么让关键字不能与eval()一起使用

function foo(str, a) {
  eval( str );
  console.log( a, b );
}

foo( "var b = 3;", 1 ); 
Run Code Online (Sandbox Code Playgroud)

这很好用,但是当我们使用let而不是var时,它不起作用.为什么?

javascript

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

如何在javascript中实现观察者模式?

嗨,我想在JavaScript中实现观察者模式:

我的index.js:

$(document).ready(function () {
  var ironMan = new Movie();
  ironMan.setTitle('IronMan');
  ironMan.setRating('R');
  ironMan.setId(1);
  //  ironMan.setCast(['Robert Downey Jr.', 'Jeff Bridges', 'Gwyneth Paltrow']);

  var terminator = new Movie();
  terminator.setTitle('Terminator');
  terminator.setRating('P');
  terminator.setId(2);

  console.log(ironMan.toString());
  console.log(terminator.toString());

  ironMan.play();
  ironMan.stop();
  ironMan.download();
  ironMan.share('V. Rivas');

  console.log(ironMan.getCast()[0]);
});
Run Code Online (Sandbox Code Playgroud)

我的电影:

var title;
var rating;
var id;
var observers;


function Movie() {
  observers = new ObserverList();
}

//function Movie (title, rating, id){
//  this. title = title;
//  this.rating =  rating;
//  this.id =id;
//  observers = new ObserverList();
//} …
Run Code Online (Sandbox Code Playgroud)

javascript design-patterns observer-pattern

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

最小最大价格范围验证不适用于jquery.validate.js

表单验证我正在使用https://jqueryvalidation.org.我已经通过depends属性实现了自定义验证规则.

以下是验证错误规则:

  • 如果未选中两个价格框,则不会显示错误.

  • 如果选择了一个价格框(两个中的一个),则验证错误将显示用户需要同时选择两个.

  • 如果两者都被选中,那么最大价格值必须大于最低价格.

请在下面找到我的代码:

在我的代码中,每个条件都令人满意,但最后一条规则意味着最高价格总是大于最低价格不起作用.它的检查是正确的,但验证不会触发.

这里是jsfiddle链接

$(document).ready(function() {
    $("#form1").validate({
        debug: true,
        onkeyup: false,
        onfocusout: false,
        onclick: false,
        rules: {
            minrange: {
                required: {
                    depends: function() {
                        var min_range = $("#min-range").find(':selected').val(),
                            max_range = $("#max-range").find(':selected').val();
                        if (min_range == "" && max_range == "") {
                            return false;
                        } else if (min_range != "" && max_range == "") {
                            return true;
                        } else if (min_range == "" && max_range != "") {
                            return true;
                        } else if (parseInt(max_range) < …
Run Code Online (Sandbox Code Playgroud)

javascript validation jquery jquery-validate

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

Xampp控制面板在启动时显示错误

我的Xampp控制面板出现问题.一旦我尝试启动它,它会弹出一条错误消息:

"错误:无法创建文件"C:\ xampp\xampp-control.ini".访问被拒绝.

我安装的版本是xampp-win32-5.6.23.当我尝试启动apache模块时,下面是log respnse:

7:53:14 PM  [Apache]    Attempting to start Apache app...
7:53:15 PM  [Apache]    Status change detected: running
7:53:17 PM  [Apache]    Status change detected: stopped
7:53:17 PM  [Apache]    Error: Apache shutdown unexpectedly.
7:53:17 PM  [Apache]    This may be due to a blocked port, missing dependencies, 
7:53:17 PM  [Apache]    improper privileges, a crash, or a shutdown by another method.
7:53:17 PM  [Apache]    Press the Logs button to view error logs and check
7:53:17 PM  [Apache]    the Windows Event Viewer …
Run Code Online (Sandbox Code Playgroud)

php apache xampp bitnami

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

角度中的某些变量没有定义错误?

我在codepen中使用以下代码并面临此问题,对于conctact我收到以下错误

为什么它会给出错误的联系而不是名字?

我怎么解决这个问题?

angular.js:13550 ReferenceError: contact is not defined
    at new <anonymous> (pen.js:8)
    at Object.invoke (angular.js:4665)
    at R.instance (angular.js:10115)
    at n (angular.js:9033)
    at g (angular.js:8397)
    at g (angular.js:8400)
    at angular.js:8277
    at angular.js:1751
    at n.$eval (angular.js:17229)
    at n.$apply (angular.js:17329)
Run Code Online (Sandbox Code Playgroud)

这是js文件

var app = angular.module("crud", []);

app.controller("ctrl", ['$scope', function($scope) {
    $scope.data = [3, 4, 5, 34, 34];
    debugger;
    $scope.name = name;
    $scope.contact = contact;
    $scope.obj = {
        name: $scope.name,
        contact: $scope.contact
    };
    console.log($scope.obj);
}]);
Run Code Online (Sandbox Code Playgroud)

这是我正在使用的HTML文件.

<body ng-app="crud">
  <div ng-controller="ctrl">       
    <div>
      <table>
        <tr …
Run Code Online (Sandbox Code Playgroud)

html javascript angularjs

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

JavaScript原型覆盖

我是学习JavaScript概念的新手.想了解原型继承是如何工作的.我的印象是,如果您的类继承了它的父级,并且在两个类的原型中都有相同的命名方法,当您在子实例上调用该方法时,将调用子原型中的方法.

码:

function Animal(name) {
    this.name = name;
}

Animal.prototype.printName = function () {
    console.log(this.name + ' in animal prototype');
}

function Cat(name) {
    Animal.call(this, name);
}



Cat.prototype.printName = function () {
    console.log(this.name + ' in cat prototype');
}

Cat.prototype = Object.create(Animal.prototype);

var anm1 = new Animal('mr cupcake');
anm1.printName();


var cat1 = new Cat('cat');
cat1.printName();
Run Code Online (Sandbox Code Playgroud)

在调用cat1.printName()时,我希望它能记录'cat in cat prototype',但它记录了'cat in Animal prototype'.有人可以向我解释一下原因.谢谢.

javascript prototype

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

如何用函数改变ng-init值?

这是我的Html和JavaScript代码,我想通过函数更改它.

Html:

<div class="container" ng-app="myApp" ng-controller="myController">
  <h2>{{title}}</h2>
  <ul ng-init="initItems()">
    <li ng-repeat="item in items">
      <input ng-model="item.name" type="text"/>
      <div ng-if="makeVisible == item.id  && makeVisible !='' ">
        <input ng-model="newname" type="text"/>
        <button ng-click="hideme(item.id);  rename()" type="button">
          <span class="glyphicon glyphicon-ok">
          </span>
        </button>
        <button ng-click="hideme(item.id)" type="button">
          <span class="glyphicon glyphicon-remove">
          </span>
        </button>
      </div>
      <input ng-click=" showme( item.id)" type="button" value="Rename"/>
    </li>
  </ul>
</div>
Run Code Online (Sandbox Code Playgroud)

JavaScript:

function item(id, name) {
    this.id = id;
    this.name = name;
};

angular.module('myApp', []).controller('myController', function($scope) {
    $scope.items = [];
    $scope.makeVisible = "";
    $scope.initItems = …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs

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