这令我感到困惑。如何制作以下json函数...
$.mfjson = function() {
var mjson = { LinkToDesktopSite : [
{"section":"aboutus","name":"DemoA","mobile":"demoa.htm","desktop":"/desktop/demoa.aspx"},
{"section":"google","name":"DemoB","mobile":"demob.htm","desktop":"http://www.google.com"}
]};
}
...与另一个函数中的.each方法进行通信...
$.loopjson = function() {
$.each(mfjson().mjson.LinkToDesktopSite, function(key,value) {
var external = "www.";
if((value['mobile'] == url)) {
if((value['desktop'].indexOf(external) == -1)) {
$('.readmore').attr("href","https://www.mysite.org"+value['desktop']);
}else{
$('.readmore').attr("href",value['desktop']);
}
}
});
}
获取firebug控制台错误说.loopjson不知道mfjson是什么。
感谢您的任何建议!
答案 0 :(得分:0)
我想我明白了。添加了“将mjson返回到第一个函数和$ .mfjson()。LinkToDesktopSite到附加函数...
$.mfjson = function() {
var mjson = { LinkToDesktopSite : [
{"section":"aboutus","name":"DemoA","mobile":"demoa.htm","desktop":"/desktop/demoa.aspx"},
{"section":"google","name":"DemoB","mobile":"demob.htm","desktop":"http://www.google.com"}
]};
return mjson;
}
$.loopjson = function() {
$.each($.mfjson().LinkToDesktopSite, function(key,value) {
var external = "www.";
if((value['mobile'] == url)) {
if((value['desktop'].indexOf(external) == -1)) {
$('.readmore').attr("href","https://www.mysite.org"+value['desktop']);
}else{
$('.readmore').attr("href",value['desktop']);
}
}
});
}