for jq 嵌套_jQuery .each()嵌套数组中

我对这篇长文章表示歉意,但我会给你完整的故事。我有一个页面列出了一些产品,下面每个页面都有一个jQueryUI日历来选择一个交货日期。我不会理解为什么,但我必须做我正在做的与客户端脚本相关的工作。

我使用jQuery来遍历每个产品名称。对于每一个,它都会检查一组关键字,并在产品名称在数组中的任何位置找到时采取相应措施。

结束操作将使用对相关日历日期选择器的调用并对其应用最小和最大日期(这很容易)。

我现在遇到的问题是,我决定使用嵌套数组作为产品名称和允许选择交付产品的日期。因此,我不是只有一组关键字,而是:

var keywordArray = [

//product name, start date, end date

["foo","2/1/2014","2/13/2014"],

["bar","2/7/2014","2/12/2014"]

];所以“foo”只能在2/1和2/13之间传递。

鉴于此,我的内循环需要经过修改,但我还没有弄清楚如何去做。当数组只是一个简单的关键字数组时,它工作得很好,但是现在我需要测试数组数组中每个数组的第一个元素(多少)。

function checkAllowedDates() {

$("div[id^='delivery_product_name_']").each(function(index) { //outer loop (each product name)

str = $("div#delivery_product_name_"+parseInt(index+1)).text(); //gets text inside 'delivery_product_name_1', _2, etc...

$.each(keywordArray,function(index,value){ //test all array values to see if any are in the product name

if (str.toLowerCase().indexOf(value) >= 0) { //contains a keyword

console.log(str+ " contains the special keyword " + value);

}

});

});

}我尝试使用值[0],没有骰子。我搜索/ binged如何使用嵌套数组,并发现了一些很好的例子,我可以使用正常的for循环,但我真的想在这上面使用jQuery。

这么简单的表单:我如何使用$ .each()循环访问数组数组,并测试每个内部数组(产品名称字符串)的第0个索引,以查看它是否与我外部循环的当前产品名称文本匹配?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
import tushare as ts import datetime # 设置 token,用于认证 ts.set_token('530fbc2b682d65696dbeec010a893f70d6953fbb6842151003c3e12f') # 初始化 tushare pro = ts.pro_api() df = pro.daily(fields = 'ts_code,trade_date,open,close',start_date='20180701', end_date='20180718') def get_stock_poll(df): stock_pool=[] for code in df['ts_code'].unique(): temp_df = df[df['ts_code'] == code ] for i in range(len(temp_df)-3): if (temp_df.iloc[i + 3]['close'] > temp_df.iloc[i + 2]['close']) and \ (temp_df.iloc[i + 2]['close'] > temp_df.iloc[i + 2]['open']) and \ (temp_df.iloc[i + 1]['close'] > temp_df.iloc[i + 1]['open']) and \ (temp_df.iloc[i]['close'] > temp_df.iloc[i]['open'])and \ (temp_df.iloc[i + 3]['close'] > temp_df.iloc[i + 2]['close'])and \ (temp_df.iloc[i + 2]['close'] > temp_df.iloc[i + 1]['close']) and\ (temp_df.iloc[i + 1]['close'] > temp_df.iloc[i]['close']): stock_pool.append(code) break return stock_pool def buy_stock(stock_pool,df): buy_list = [] for code in stock_pool: temp_df = df[df['ts_code']==code] for i in range(len(temp_df-2)): if(temp_df.iloc[i + 2]['close'] < temp_df.iloc[i + 2]['open']) and \ (temp_df.iloc[i + 1]['close'] < temp_df.iloc[i + 1]['open']) and \ (temp_df.iloc[i]['close'] < temp_df.iloc[i]['open'])and \ (temp_df.iloc[i + 2]['close'] < temp_df.iloc[i + 1]['close'])and \ (temp_df.iloc[i + 1]['close'] < temp_df.iloc[i]['close']): buy_list.append(code) break return buy_list def sell_stock(buy_stock,df): sell_list = [] for stock in buy_list: buy_date=dateime.datetime.strptime(stock[1],"%Y-%m-%d") current_date = datetime.datetime.today() days_held = (current_date - buy_date).days if days_held >=3: sell_list.append(stock[0]) print("sell list:",sell_list)要求上述代码在聚宽上运行
06-01

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值