jsonEncode owl carousel 2 响应配置如何
How do jsonEncode owl carousel 2 responsive config
case 'carousel':
return $helper->jsonEncode(array(
'dots' => (bool) $this->getData('paging'),
'autoPlay' => is_numeric($this->getData('autoplay')) ? true : false,
'autoplayTimeout' => is_numeric($this->getData('autoplay')) ? (int) $this->getData('autoplay') : false,
'autoplayHoverPause' => true,
'loop' => true,
'lazyLoad' => true,
'responsive' => '{
0:{items:1,nav:true},
768:{items:2,nav:false},
992:{items:3,nav:true}
}',
'nav' => (bool) $this->getData('navigation'),
'navText' => array($this->getData('navigation_prev'), $this->getData('navigation_next'))
));
这是错误:
Uncaught TypeError: Cannot use 'in' operator to search for 'length' in {
0:{items:1,nav:true},
768:{items:2,nav:false},
992:{items:3,nav:true}
}
如何解决这个问题?谢谢
json_encode()
与数组一起使用,你不应该传递 JSON 字符串
变化:
'responsive' => '{
0:{items:1,nav:true},
768:{items:2,nav:false},
992:{items:3,nav:true}
}',
至:
'responsive'=> array(
0=>array('items'=>1,'nav'=>true),
768=>array('items'=>2,'nav'=>false),
992=>array('items'=>3,'nav'=>true)
),
case 'carousel':
return $helper->jsonEncode(array(
'dots' => (bool) $this->getData('paging'),
'autoPlay' => is_numeric($this->getData('autoplay')) ? true : false,
'autoplayTimeout' => is_numeric($this->getData('autoplay')) ? (int) $this->getData('autoplay') : false,
'autoplayHoverPause' => true,
'loop' => true,
'lazyLoad' => true,
'responsive' => '{
0:{items:1,nav:true},
768:{items:2,nav:false},
992:{items:3,nav:true}
}',
'nav' => (bool) $this->getData('navigation'),
'navText' => array($this->getData('navigation_prev'), $this->getData('navigation_next'))
));
这是错误:
Uncaught TypeError: Cannot use 'in' operator to search for 'length' in { 0:{items:1,nav:true}, 768:{items:2,nav:false}, 992:{items:3,nav:true} }
如何解决这个问题?谢谢
json_encode()
与数组一起使用,你不应该传递 JSON 字符串
变化:
'responsive' => '{
0:{items:1,nav:true},
768:{items:2,nav:false},
992:{items:3,nav:true}
}',
至:
'responsive'=> array(
0=>array('items'=>1,'nav'=>true),
768=>array('items'=>2,'nav'=>false),
992=>array('items'=>3,'nav'=>true)
),