创建另一个变量的变量(json,getJson方法)
Create a variable of another variable (json, getJson method)
我有以下可行的例子:"ratioSize":"LP555/12317 Z ABCD"
在我的 getJson 调用中的每个函数中:
$.each(data.infoData, function (i, item) {
// console.log(Rating); works just fine
//console.log(stockNumber ); works just fine
var Rating = this.tireRating;
var stockNumber = this.SN;
var ratioSize = this.TS
var NEW_VARIALBE_I_NEED = the last 2 number of the FIRST PART of ratioSize, so in this case it is 17
});
关于如何将它变成我的变量之一的任何想法?我完全迷失在这里
我不太确定你在问什么,为了得到你想要的字符,请这样做:
var Rating = this.tireRating;
var stockNumber = this.SN;
var ratioSize = this.TS
var ratioSplit=ratioSize.split(' ');
var variable=ratioSize.slice(ratioSplit[0].length-2,ratioSplit[0].length);
根据您的示例,变量现在为 17。
假设“17”字符串的位置和长度不变,我们可以简单地抓取一个子字符串:
var ratioSize = "LP555/12317 Z ABCD";
var result = ratioSize.substring(9, 11);
我有以下可行的例子:"ratioSize":"LP555/12317 Z ABCD"
在我的 getJson 调用中的每个函数中:
$.each(data.infoData, function (i, item) {
// console.log(Rating); works just fine
//console.log(stockNumber ); works just fine
var Rating = this.tireRating;
var stockNumber = this.SN;
var ratioSize = this.TS
var NEW_VARIALBE_I_NEED = the last 2 number of the FIRST PART of ratioSize, so in this case it is 17
});
关于如何将它变成我的变量之一的任何想法?我完全迷失在这里
我不太确定你在问什么,为了得到你想要的字符,请这样做:
var Rating = this.tireRating;
var stockNumber = this.SN;
var ratioSize = this.TS
var ratioSplit=ratioSize.split(' ');
var variable=ratioSize.slice(ratioSplit[0].length-2,ratioSplit[0].length);
根据您的示例,变量现在为 17。
假设“17”字符串的位置和长度不变,我们可以简单地抓取一个子字符串:
var ratioSize = "LP555/12317 Z ABCD";
var result = ratioSize.substring(9, 11);