javascript 中的角度过滤数据不显示结果,数据推送导致错误 plunker 提供 [英] Angular filtering data in javascript is not displaying results and push of data causes error plunker provided

查看:18
本文介绍了javascript 中的角度过滤数据不显示结果,数据推送导致错误 plunker 提供的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我的 Angular 站点的设置方式似乎有太多问题,所以我把它放在一个 plunker 中,这样任何人都可以看到它.

原始问题:Angular 将特定数据检索到 $范围变量不起作用

Plunkerhttp://plnkr.co/edit/NsE29zjraQp9UeklJBiI?p=preview

我的问题是1. 我不明白如何使用 app.filter2. 应用名称问题3. forEach with push inside $http.get 抛出未定义错误

plunker Index.html 有模板代码循环,app.module.js 是 root,device.controller.js 是我使用控制器和 $http.get 调用使用 json 文件来伪造它的地方.

>

我试图使用其他人的答案,所以这段代码

$scope.devices = result.data.Devices;//给出所有数据...

过滤器我想知道这是否有用

{{ device.DeviceStatus }}

然后这段代码我不确定它在正确的位置"

好像我不理解应用程序"

app.filter('deviceStatus', function () {返回函数(status_id){var statuses = ['旧设备', '新设备', '已激活', '未激活'];返回状态[status_id];};});

示例过滤器:

{{device.DeviceId |设备状态}}</td>

解决方案

让我试着了解您的问题.

根据您的问题,您似乎在理解 app 是什么以及如何使用 filter 时遇到问题.

这是您的 plunkr 的工作版本.检查这个网址

  1. app 在您的项目中是 ng-app 指令.ng-app 指令告诉 AngularJS 该元素是 AngularJS 应用程序的所有者".
  2. 用于了解过滤器功能.检查下面的例子.
  3. 您试图推送到尚未定义的 $scope.statuses.所以首先定义 $scope.statuses 为一个空数组,即 `$scope.statuses = [];

希望这对你有用!`

//要声明过滤器,我们将两个参数传递给 app.filter//第一个参数是过滤器的名称//第二个是一个函数,它将返回另一个执行过滤器实际工作的函数//这里app是你项目的模块名app.filter('myFilter', function() {//在返回函数中,我们必须传入一个参数,这将是我们将要处理的数据.//我们有能力支持多个可以选择性地传入过滤器的其他参数返回函数(输入,可选1,可选2){无功输出;//在这里做过滤工作返回输出;}});

Ok, seems that I was having too many issues with the way in which my Angular site is setup, so I put it in a plunker as then anyone can see it.

Original question: Angular retrieve specific data into $scope variable is not working

Plunker http://plnkr.co/edit/NsE29zjraQp9UeklJBiI?p=preview

My issues are 1. i'm not understanding how to use app.filter 2. Issue with app name 3. forEach with push inside $http.get throws error not defined

The plunker Index.html has the template code loop , app.module.js is root and the device.controller.js is where I'm using controller with $http.get call using json file to fake it.

I was attempting to use the other persons answer so this code

$scope.devices = result.data.Devices;   // gives all data ... 

Filter I was wondering if this with work

<div ng-repeat="device in devices">
    {{ device.DeviceStatus }} 
</div>

Then this code I'm not sure it in the correct "place"

seems like i'm not understanding "app"

app.filter('deviceStatus', function () {
    return function (status_id) {
       var statuses = ['Old Device', 'New Device', 'Activated', 'Unactivated'];
       return statuses[status_id];
   };
});

Example filter:

<td>{{device.DeviceId | deviceStatus}}</td>

解决方案

Let me try to understand your issue.

As per your question, it seems that you have problems understanding what app is and how to use filter.

This is the working version of your plunkr. Check this url

  1. app in your project is the ng-app directive. The ng-app directive tells AngularJS that the element is the "owner" of an AngularJS application.
  2. For understanding filter functionality. check the below example.
  3. You were trying to push into $scope.statuses which is not defined yet. So first define $scope.statuses to be an empty array i.e `$scope.statuses = [];

Hope this works for you!`

// To declare a filter we pass in two parameters to app.filter

// The first parameter is the name of the filter 
// second is a function that will return another function that does the actual work of the filter

//here app is the module name of your project

app.filter('myFilter', function() {

  // In the return function, we must pass in a single parameter which will be the data we will work on.
  // We have the ability to support multiple other parameters that can be passed into the filter optionally
  return function(input, optional1, optional2) {

    var output;

    // Do filter work here

    return output;

  }

});

这篇关于javascript 中的角度过滤数据不显示结果,数据推送导致错误 plunker 提供的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆