var arrPropertiesAndChannels = null, arrPrrp = null, arrLeftProp = null, arrMiddleDefault = null, arrRightProp = null;
$(document).ready(function () {
arrPropertiesAndChannels = { "props": [{ "prid": "61494", "prname": "Park Plaza Hotel Gurgaon", "pos": "1", "pinned": false, "display": true }, { "prid": "62998", "prname": "Lemon Tree City Center", "pos": "2", "pinned": false, "display": true }, { "prid": "62999", "prname": "Lemon Tree Hotel Udyog Vihar", "pos": "3", "pinned": false, "display": true }, { "prid": "78097", "prname": "Royal Retreat", "pos": "4", "pinned": false, "display": false }, { "prid": "78098", "prname": "SkRetreat", "pos": "5", "pinned": false, "display": false }, { "prid": "78099", "prname": "VBkRetreat", "pos": "6", "pinned": false, "display": false}], "chans": [{ "chid": "1", "chname": "FACEBOOK", "pos": "1" }, { "chid": "2", "chname": "TWITTER", "pos": "2" }, { "chid": "3", "chname": "NEWSLETTER", "pos": "3"}] };
arrPrrp = arrPropertiesAndChannels.props;
arrLeftProp = arrPrrp.slice(0, 0);
arrMiddleDefault = arrPrrp.slice(0, 3);
arrRightProp = arrPrrp.slice(3, 8);
});
function navigRight() {
var tempprid = '';
$.each(arrMiddleDefault, function (i, data) {
console.log(data.prid);
if (data.pinned == false) {
arrLeftProp.push(data);
tempprid = data.prid;
//console.log(tempprid);
//break;
}
});
arrMiddleDefault = arrMiddleDefault.filter(function (el) {
return el.prid !== tempprid;
});
arrMiddleDefault.push(arrRightProp.slice(0, 1));
//console.log(arrMiddleDefault);
//console.log(arrLeftProp);
arrRightProp = arrRightProp.filter(function (el) {
return el.prid !== arrRightProp.slice(0, 1)[0].prid;
});
}
<div>
<input type="button" value="<<" onclick="navigLeft()">
<div id="dvTest">
</div>
<input type="button" value=">>" onclick="navigRight()">
</div>
我有 json 数据变量
arrPropertiesAndChannels ={ "props": [{ "prid": "61494", "prname": "Park Plaza Hotel Gurgaon", "pos": "1", "pinned": false, "display": true }, { "prid": "62998", "prname": "Lemon Tree City Center", "pos": "2", "pinned": false, "display": true }, { "prid": "62999", "prname": "Lemon Tree Hotel Udyog Vihar", "pos": "3", "pinned": false, "display": true }, { "prid": "78097", "prname": "Royal Retreat", "pos": "4", "pinned": false, "display": false }, { "prid": "78098", "prname": "SkRetreat", "pos": "5", "pinned": false, "display": false }, { "prid": "78099", "prname": "VBkRetreat", "pos": "6", "pinned": false, "display": false}], "chans": [{ "chid": "1", "chname": "FACEBOOK", "pos": "1" }, { "chid": "2", "chname": "TWITTER", "pos": "2" }, { "chid": "3", "chname": "NEWSLETTER", "pos": "3"}] };
我们有
arrPrrp = arrPropertiesAndChannels.props;
arrLeftProp = arrPrrp.slice(0, 0);
console.log(arrLeftProp);
arrMiddleDefault = arrPrrp.slice(0, 3);
console.log(arrMiddleDefault);
arrRightProp = arrPrrp.slice(3, 8);
console.log(arrRightProp);
我有一个按钮值是“>>”。单击此按钮时,javascript navigRight() 函数调用...其中 arrMiddleDefault 的第一项被推入 arrLeftProp 数组。这次从 arrMiddleDefault 数组中删除第一项,并将 arrRightProp 的第一项插入到 arrMiddleDefault 数组中。第一次单击按钮“>>”console.log(data.prid) 在 navigRight() 函数中给出 61494,62998,62999。第二次 console.log(data.prid) 给出 61494,62998,undefined, 第三次 console.log(data.prid) 给出 61494,undefined,undefined, 第四次 console.log(data.prid) 给出 undefined,undefined,undefined