小编iam*_*box的帖子

返回深度嵌套数组中对象索引的函数

我可能需要编写一个只输出数组内对象索引的函数,显然,在下面的示例中使用 $.inArray 返回它就好了。

array = ['one', 'two', 'three'];

$.inArray('one', array) // 0
Run Code Online (Sandbox Code Playgroud)

使用更精细的数组,如何找到嵌套在其中的对象的索引?

array = [
    {
        name: 'One', // index??
        data: {
            title: 'Title One',
            content: 'Content One'
        }
    },
    {
        name: 'Two',
        data: {
            title: 'Title Two',
            content: 'Content Two'
        }
    },
    {
        name: 'Three',
        data: {
            title: 'Title Three',
            content: 'Content Three'
        }
    }
];
Run Code Online (Sandbox Code Playgroud)

我听说过 $.grep() 方法, indexOf() .. 不确定使用哪个方法只返回对象所在索引的整数

javascript arrays indexing

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

多个快捷方式图标?

我今天看到这个,并想知道如何实现它?我正在寻找另一个例子,但同时也会在这里提出问题.

在此输入图像描述

html favicon

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

Mongoimport导入json数组作为集合而不是集合中的键

我试图使用mongoimport为json数据数据种子数据库,但是当数据到达mongo集合时,它作为集合对象中的一个键导入,如下所示:

[![在此输入图片说明] [1]] [1]

"items"是我的json文件,它总是显示为"items",我希望父数组是我试图导入的数组,这有意义吗?

更新

请看这个例子,第一个图像是mongoimport如何导入这个对象数组:

{ "_id" : ObjectId("58dc01ecec116d4c9039e47c"), "items" : [ { "id" : 1, "_id" : "item1", "type" : "alert", "title" : "hello.world", "email" : "something@something.com", "message" : "", "createdDate" : "date", "price" : "$9.00", "active" : true }, { "id" : 2, "_id" : "item2", "type" : "welcome.lol", "title" : "Item 2", "email" : "something@something.com", "message" : "lol", "createdDate" : "date", "price" : "$12.00", "active" : true }, { "id" : 3, "_id" : "item3", …
Run Code Online (Sandbox Code Playgroud)

mongodb mongoimport

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

Div点击相同的单选按钮?

有没有办法让div上的click事件与表单环境中的单选按钮相同?我只想让下面的div提交值,单选按钮很难看

在此输入图像描述

代码输出如下:

<input id="radio-2011-06-08" value="2011-06-08" type="radio" name="radio_date">8</input></li><li id="li-2011-06-09" class=" "><input id="radio-2011-06-09" value="2011-06-09" type="radio" name="radio_date">9</input></li><li id="li-2011-06-10" class=" "><input id="radio-2011-06-10" value="2011-06-10" type="radio" name="radio_date">10</input></li><li id="li-2011-06-11" class=" end "><input id="radio-2011-06-11" value="2011-06-11" type="radio" name="radio_date">11</input></li><li id="li-2011-06-12" class=" start "><input id="radio-2011-06-12" value="2011-06-12" type="radio" name="radio_date">12</input></li><li id="li-2011-06-13" class=" "><input id="radio-2011-06-13" value="2011-06-13" type="radio" name="radio_date">13</input></li><li id="li-2011-06-14" class=" "><input id="radio-2011-06-14" value="2011-06-14" type="radio" name="radio_date">14</input></li><li id="li-2011-06-15" class=" "><input id="radio-2011-06-15" value="2011-06-15" type="radio" name="radio_date">15</input></li><li id="li-2011-06-16" class=" "><input id="radio-2011-06-16" value="2011-06-16" type="radio" name="radio_date">16</input></li><li id="li-2011-06-17" class=" "><input id="radio-2011-06-17" value="2011-06-17" type="radio" name="radio_date">17</input></li><li id="li-2011-06-18" class=" end "><input id="radio-2011-06-18" value="2011-06-18" type="radio" name="radio_date">18</input></li><li …
Run Code Online (Sandbox Code Playgroud)

php forms jquery

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

打印 SESSION 中的所有登录用户?

我有一个支持大约 80 个用户的 SESSION,我想打印他们所有的用户名并每 60 秒左右刷新一次页面。我知道如何刷新页面,但<?php print_r($_SESSION['username']); ?>只打印与我的个人会话相关联的用户名。

php variables session

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

jQuery一次显示一个元素?

我有一个索引类的列表 - 在容器div的fadeIn上一次显示这些类的最佳方法是什么?

jquery show

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

jQuery动画摇动悬停

我试图在没有使用jQuery UI的情况下悬停元素并且遇到以下代码,但是我似乎无法弄清楚如何在悬停时触发,此代码具有随机效果并且每次我尝试时都会让我感到困惑弥漫它.我试图让他们一次动画一个,而不是完全

http://jsfiddle.net/g6AeL/

   $(function() {
      var interval = 10;
      var duration= 1000;
      var shake= 3;
      var vibrateIndex = 0;
      var selector = $('aside.featured a'); /* Your own container ID*/
        $(selector).click( /* The button ID */

        function(){ 

        vibrateIndex = setInterval(vibrate, interval);
        setTimeout(stopVibration, duration);

        });

        var vibrate = function(){
        $(selector).stop(true,false)
        .css({position: 'relative', 
        left: Math.round(Math.random() * shake) - ((shake + 1) / 2) +'px', 
        top: Math.round(Math.random() * shake) - ((shake + 1) / 2) +'px'
        });
        }

        var stopVibration = function() {
        clearInterval(vibrateIndex); …
Run Code Online (Sandbox Code Playgroud)

random jquery jquery-animate

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

Angular ui-select2指令不适用于AngularJS Validation

我已经搜索了互联网试图弄清楚为什么专有的AngularJS验证在使用jQuery.Select2和ui-select2指令时不起作用- 这是一个错误?

编辑:好的我发现它只是标记输入正在发生,我的选择下拉菜单和文本输入工作正常.

这是小提琴 http://jsfiddle.net/whiteb0x/ftEHu/

HTML:

  <form name="myForm" ng-controller="Ctrl">
    userType: <input ui-select2="version1" class="input-xlarge" type="hidden" name="input" ng-model="userType" required>
    <span class="error" ng-show="myForm.input.$error.required">Required</span><br>
    <tt>userType = {{userType}}</tt><br>
    <tt>myForm.input.$valid = {{myForm.input.$valid}} wtf???????!!!</tt><br>
    <tt>myForm.input.$error = {{myForm.input.$error}} huh????</tt><br>
    <tt>myForm.$valid = {{myForm.$valid}} | please hand me a gun :)</tt><br>
    <tt>myForm.$error.REQUIRED = {{!!myForm.$error.REQUIRED}}</tt><br>
   </form>
Run Code Online (Sandbox Code Playgroud)

使用Javascript:

var app = angular.module('myApp', ['ui.directives']);

function Ctrl($scope) {
  $scope.userType = '';
  $scope.version1 = {
      tags : null
  };    
}
Run Code Online (Sandbox Code Playgroud)

directive angularjs jquery-select2

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

jQuery $('element',this)选择器,它是什么意思?

我在一个函数中使用了这个选择器,我甚至不知道它究竟意味着什么,但它有效 - 这是我的代码片段:

else if($(this).hasClass('list')) {
        listItem.stop(true,true).fadeOut(333, function(){ 
        var $this = $(this);
        if(listItem.hasClass('grid')) {
            $this.find('h1', this).insertBefore($this.children());
        }

javascript jquery selector

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

用PHP编写Switch的更好方法?

我使用下面的这个例子来询问如何将数组传递给Switch,而不是像这样将它们列出来?

也许如果我从一个数据库中获取一个数组作为页面的所有"页面".

我认为这种方法不是最优雅的方法.

switch($_GET['page'])
{
case 'home':
    include('home.php');
    break;
case 'oem-customers':
    include('oem-customers.php');
    break;
case 'job-shop': 
    include('job-shop.php');        
    break;
case 'anodized-magnet-coils':
    include('anodized-magnet-coils.php');
    break;
case 'design':
    include('design.php');
    break;
case 'services':
    include('services.php');
    break;
case 'black-foil':
    include('black-foil.php');
    break;  
case 'contact':
    include('contact.php');
    break;
case 'order';
    include('order.php');
    break;
default: 
    include('home.php');
}
Run Code Online (Sandbox Code Playgroud)

php switch-statement

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