我可能需要编写一个只输出数组内对象索引的函数,显然,在下面的示例中使用 $.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() .. 不确定使用哪个方法只返回对象所在索引的整数
我试图使用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) 有没有办法让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) 我有一个支持大约 80 个用户的 SESSION,我想打印他们所有的用户名并每 60 秒左右刷新一次页面。我知道如何刷新页面,但<?php print_r($_SESSION['username']); ?>只打印与我的个人会话相关联的用户名。
我试图在没有使用jQuery UI的情况下悬停元素并且遇到以下代码,但是我似乎无法弄清楚如何在悬停时触发,此代码具有随机效果并且每次我尝试时都会让我感到困惑弥漫它.我试图让他们一次动画一个,而不是完全
$(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) 我已经搜索了互联网试图弄清楚为什么专有的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) 我在一个函数中使用了这个选择器,我甚至不知道它究竟意味着什么,但它有效 - 这是我的代码片段:
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());
}
我使用下面的这个例子来询问如何将数组传递给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)