小编DS9*_*DS9的帖子

如何在javascript中获取json编码数组的长度?

我有一个像这样的json编码数组:

{
  "ar0":"{\"start\":{\"lat\":22.9939202,\"lng\":72.50009499999999},\"end\":{\"lat\":23.0394491,\"lng\":72.51248850000002},\"waypoints\":[[23.0316834,72.4779436]]}",

  "ar1":"{\"start\":{\"lat\":22.9999061,\"lng\":72.65318300000001},\"end\":{\"lat\":23.0420584,\"lng\":72.67145549999998},\"waypoints\":[[23.02237,72.6500747]]}",

  "ar2":"{\"start\":{\"lat\":23.0394491,\"lng\":72.51248850000002},\"end\":{\"lat\":22.9999061,\"lng\":72.65318300000001},\"waypoints\":[[23.0016629,72.58898380000005]]}"

 } 
Run Code Online (Sandbox Code Playgroud)

我的疑问是:

(1)如何找到这个数组的长度? //here it is 3

(2)如何使用它的价值?
//for example:for as0 the value is {\"start\":{\"lat\":22.9939202,\"lng\":72.50009499999999},\"end\":{\"lat\":23.0394491,\"lng\":72.51248850000002},\"waypoints\":[[23.0316834,72.4779436]]}

javascript code where i use upper things :

 function setroute(os)
{
    var wp = [];
    for(var i=0;i<os.waypoints.length;i++)
        wp[i] = {'location': new google.maps.LatLng(os.waypoints[i][0], os.waypoints[i][1]),'stopover':false }

    ser.route({'origin':new google.maps.LatLng(os.start.lat,os.start.lng),
    'destination':new google.maps.LatLng(os.end.lat,os.end.lng),
    'waypoints': wp,
    'travelMode': google.maps.DirectionsTravelMode.DRIVING},function(res,sts) {
        if(sts=='OK')ren.setDirections(res);
    })  
}

function fetchdata()
{
    var jax = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
    jax.open('POST','process.php');
    jax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

    jax.send('command=fetch')
    jax.onreadystatechange = function(){ if(jax.readyState==4) {                
    alert(JSON.parse(jax.responseText).ar0);
        try { …
Run Code Online (Sandbox Code Playgroud)

javascript arrays json

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

如何找到当天没有.在PHP的月份

今天的日期是27-01-2014所以我使用以下功能得到了日名:

$t=date('d-m-Y');
$day = strtolower(date("D",strtotime($t)));
Run Code Online (Sandbox Code Playgroud)

所以今天的名字是mon.

如何发现本周一是本月的第四个星期一?换句话说,我想找到一个月的某一天(例如星期一)的第一,第二,第三,第四?

php date

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

Fabric JS中的对象对齐

我正在尝试在画布中实现对象对齐(即,右,中,左,上,下)。假设用户选择了一个对象(即“文本”或“图像”),那么如果用户单击“向右对齐”选项,则该所选对象应与右侧对齐。

我尝试了以下2种方法,但没有成功。

var canvas = new fabric.Canvas('a');
canvas.add(new fabric.Rect({
  left: 50,
  top: 50,
  height: 50,
  width: 50,
  fill: 'red'
}));
canvas.add(new fabric.Rect({
  left: 130,
  top: 50,
  height: 50,
  width: 50,
  fill: 'green'
}));
canvas.add(new fabric.Rect({
  left: 90,
  top: 130,
  height: 50,
  width: 50,
  fill: 'blue'
}));

canvas.renderAll();

$('.alignment').click(function() {
  var cur_value = $(this).attr('data-action');
  if (cur_value != '') {
    process_align(cur_value);
  } else {
    alert('Please select a item');
    return false;
  }
});

/* Align the selected object */
function process_align(val) {
  switch …
Run Code Online (Sandbox Code Playgroud)

javascript jquery html5-canvas fabricjs

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

如何从数据库中获取不同的数据?

我有一个这样的数据库表:
在此输入图像描述


我希望hostel_name根据日期与表区别开来.如果日期相同,则只提取不同的名称,但如果日期更改,那么同样的hostel_name也是fetched.just就像uper图像.
提前致谢.

php mysql

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

如何在PHP中检查这一天是该月的最后一天?

我之前的问题:how-to-find-current-day-no-in-month-in-php

现在我面临另一个问题。假设我知道这monday4th monday of the current month.现在如何检查this monday is also the last monday of the current month

exa:1 
date: 27-01-2014
Run Code Online (Sandbox Code Playgroud)

使用下面的代码,我可以获得一天的名称和数字:

day: monday   
day no :4th
Run Code Online (Sandbox Code Playgroud)

这是一月的第四个星期一,也是一月的最后一个星期一。如何检查?

exa:2  
date: 20-01-2014   
day: monday   
day no :3rd
Run Code Online (Sandbox Code Playgroud)

这里this monday is 3rd monday of january but not last monday of january.

那么,简而言之,当我得到一个天数时,如何检查该天数是否是最后一个呢?

code:

$t=date('d-m-Y');
$dayName = strtolower(date("D",strtotime($t)));
$dayNum = strtolower(date("d",strtotime($t)));
$dayno = floor(($dayNum - 1) / 7) + 1
Run Code Online (Sandbox Code Playgroud)

php date

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

使用Fabric JS使背景图像适合画布大小

我正在尝试拉伸背景图像,以使其适合画布大小。但是它不起作用。

我遵循了这个问题,并根据评论,我实施了扩展代码。

使用Fabric.js将背景图片拉伸到画布大小,网址为
http://fabricjs.com/docs/fabric.Canvas.html#setBackgroundImage

$(function () {     
    var canvas1 = new fabric.Canvas('canvas1');
            //Default
    var canvas = canvas1;

    //Change background using Image
    document.getElementById('bg_image').addEventListener('change', function (e) {
        canvas.setBackgroundColor('', canvas.renderAll.bind(canvas));
        canvas.setBackgroundImage(0, canvas.renderAll.bind(canvas));
        var file = e.target.files[0];
        var reader = new FileReader();
        reader.onload = function (f) {
            var data = f.target.result;
            fabric.Image.fromURL(data, function (img) {
                img.set({
                    width: canvas.getWidth(), 
                    height: canvas.getHeight(), 
                    originX: 'left', 
                    originY: 'top'
                });
                canvas.setBackgroundImage(img, canvas.renderAll.bind(canvas));
                /*canvas.setBackgroundImage(img, canvas.renderAll.bind(canvas), {
                    width: canvas.getWidth(),
                    height: canvas.getHeight(),
                    originX: 'left',
                    originY: 'top',
                    crossOrigin: 'anonymous'
                });*/
            });
        }; …
Run Code Online (Sandbox Code Playgroud)

javascript canvas fabricjs

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

获取结构js中所选对象的z-index

我想在fabric js中获取所选对象的z-index.有办法实现吗?

var z_index = 1;
$('#manage_index').change(function(){
    var cur_value = $(this).val();
    if(cur_value!='')
    {
        var object = canvas.getActiveObject();
        if(cur_value=='up') // Means increase z-index
        {
            canvas.moveTo(object, z_index);
            z_index = z_index + 1;
        }
        else if(cur_value=='back') //Means decrease z-index
        {

            //var temp_index = 0; // If set it to 0, it will goes into backward, 
            //But i am trying to implement something like below
            var temp_index = canvas.get('z-index');// Get the z-index of selected object and then decrease it
            canvas.moveTo(object, temp_index-1);
        }
    }
     $(this).val(''); …
Run Code Online (Sandbox Code Playgroud)

javascript jquery canvas fabricjs

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

如何使用其他下拉列表中未选中的选项填充下拉列表?

我使用JQuery Steps.In第一步和第二步,我有一个带有多个选择选项的下拉列表.

<select name="numbers" id="numbers">
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
  <option value="6">6</option>
</select>
Run Code Online (Sandbox Code Playgroud)

在step2中(与step1相同但具有diff目的)

<select name="allocate_numbers" id="allocate_numbers">
  <option value="1">1</option>
   : : :
 </select>
Run Code Online (Sandbox Code Playgroud)

现在我在第3步中有第3个下拉列表.在这里我想要selectbox 1,2,如步骤1中的步骤1中的用户选择3,4.

现在,我想要只5,6在步骤3中包含的选择框.
怎么做?

旁注:我做了验证,以防止重复输入step1和step2下拉列表.表示如果用户在步骤1中选择1,2,则他不能在步骤2中选择1,2.我没有为我的排名找到合适的标题,所以随时编辑它.

javascript php jquery

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

Yii2中的会话超时

我已经使用内置的yii2函数来设置会话.由于某些要求,我无法使用内置的yii2登录.

所以我使用以下设置会话:

Yii :: $ app-> session-> set('unique_code','xxxx');

在我的config/main.php文件中

'session' => [
        // this is the name of the session cookie used for login on the frontend
        'name' => 'project-frontend',
        'timeout' => 60*60*24*30,
    ],
Run Code Online (Sandbox Code Playgroud)

但是一段时间后用户仍然会从网站注销.

那么在这种情况下如何增加会话超时?

php session yii2

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

标签 统计

javascript ×5

php ×5

fabricjs ×3

jquery ×3

canvas ×2

date ×2

arrays ×1

html5-canvas ×1

json ×1

mysql ×1

session ×1

yii2 ×1