gpt4 book ai didi

javascript - 如何在onsen ui的pushpage方法中传递多个值

转载 作者:行者123 更新时间:2023-12-03 08:46:42 24 4
gpt4 key购买 nike

你好,我是 angulajs 和 javasript 的新手,我正在做一个在 onsen uipushpage 函数中传递值的演示。我已经成功地在推送页面中仅传递了一个值,但是当我尝试传递两个值时它没有传递,所以任何人都可以帮助我解决这个问题,我已尝试如下:

( Controller 内部)

var Content = ' ';
var resid = ' ';
var catname = ' '
var options,
elem,
obj = {};


for (i = 0 ; i< data ['Details'].length ; i++)
{
resid= + data['Details'][i]['intGlCode'] ;
catname = data['Details'][i]['varName'];

obj['params'] = resid;
obj['params1'] = catname;
options = JSON.stringify(obj);
console.log(options);
elem = "<li class='list__item list__item--chevron' onclick=gallery.pushPage('list-page.html', "+options+");>";
console.log(elem);
if (Content === ' ')
{
//{params:'+resid+',params1 : '+catname+'}

Content =elem+
// '<li class="list__item list__item--chevron" onclick=gallery.pushPage("list-page.html", { params: '+resid+' });>'+

'<ons-icon class="ons-icon ons-icon--ion ion-android-restaurant fa-lg" fixed-width="true" icon='+data['Details'][i]['varIcon']+'>'+'</ons-icon>'

最佳答案

您需要创建 pushPage() 参数对象首先使用括号表示法,允许您注入(inject)属性值。氧创建对象后,您可以将其解析为与 Controller 中的字符串连接的字符串。下面演示了这一点

var options, 
elem,
obj = {},
resid = 'foo',
catname = 'bar';
obj['params'] = resid;
obj['params1'] = catname;
options = JSON.stringify(obj);
console.log(options);
elem = "<li class='list__item list__item--chevron' onclick=gallery.pushPage('list-page.html', "+options+");>";
console.log(elem); /* prints <li class='list__item list__item--chevron' onclick=gallery.pushPage('list-page.html', {"params":"foo","params1":"bar"});> */

查看下面的演示。

var options, 
elem,
obj = {},
resid = 'foo',
catname = 'bar';
obj['params'] = resid;
obj['params1'] = catname;
options = JSON.stringify(obj);
console.log(options);
elem = "<li class='list__item list__item--chevron' onclick=gallery.pushPage('list-page.html', "+options+");>";

pre.innerHTML = elem;
<pre id="pre"></pre>

关于javascript - 如何在onsen ui的pushpage方法中传递多个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32860153/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com