
public class Test { /
@param args
/
public static void main(String[] args) {
// TODO Auto-generated method stub
int row=5; //这里控制输出的行列 请保证行列相等,这里就不做判断了
int[][] a=new int[row][row];
a[0][0]=1;
int n=2,zero=0,change=1;
int value=2;
for(int i=1;i<row;i++){
for(int j=0;j<(2n-1);j++){
if(i%2!=0){
if(j<(2n-2)/2){
a[zero++][change]=value++;
continue;
}
if(j==(2n-2)/2){
a[j][j]=value++;
}
if(j>(2n-2)/2){
a[change][--zero]=value++;
}
}else{
if(j<(2n-2)/2){
a[change][zero++]=value++;
continue;
}
if(j==(2n-2)/2){
a[j][j]=value++;
}
if(j>(2n-2)/2){
a[--zero][change]=value++;
}
}
}
n++;
change++;
zero=0;
}
String out="";
for(int i=0;i<row;i++){
for(int j=0;j<row;j++){
out=""+a[i][j];
if(outlength()==1)
out="0"+out;
Systemoutprint(out+" ");
}
Systemoutprintln();
}
}}
运行测试通过
1、参数接受一个对象,以key,value的形式表示;
2、参数和变量名称一致,可用一个值代替(es6新语法特性)
3、可以设置一个或多个data数据
4、key可以以数据路径的形式给出(路径形式的key必须带引号)(经小程序更新后,现已支持不加引号的写法)
5、key值可以为变量,为变量的时候要用[ ]引起来
注意:deletedtodo为变量作为key值的时候要用 [] 包裹起来。
6、直接修改thisdata,虽然会改变数据,但是页面不会重新渲染,无法改变页面状态,会造成数据不一致的情况
7、单次设置的数据不能超过1024KB,请尽量避免一次设置过多的数据
8、不需要在thisdata中预先定义,使用setData()方法会自动创建该数据
name在thisdata中未定义,但是这种写法不会报错,而且还会在thisdatazhong创建name这条数据。可以用thisdataname获取到该条数据
1、数组的增加:
我们可以自己组装一个对象如上图的obj,然后用push()方法将其添加到数据的最后。注意push的数据的index是+1的,也就是说原本数组中index依次为0,1,2,新增加的就是3,依次类推。如果想将数据插入到数据某个位置,那么可以合理运用concat()的方法将数据合并到数据中。
也可以用splice()方法添加,第一个参数是插入的位置,第二个参数设为0,则为添加,若为大于0的的数字则为要删除的个数,第三个参数只有在第二个参数为0是使用,是添加的内容。这种方法非常灵活,只需要改变第一个参数就可以将内容添加到数据的任何一个地方。下面附上splice的用法;
2、数组的删除:
删除也是用splice()方法实现的,ceshisplice(1,1)就是从index为1的位置开始,删除1个元素。splice()用法参上。
3、数组的修改:
将key值以数据路径的形式赋值,可以达到修改数据中的某一条,此处,我们只将ceshi[0]value的值改变为'oooo',其他数据未发生变化。
也可以用这种方法修改数组的参数,对这种方法有疑问的可以参考setData()第二条。
</span></span></p>";
[self flattenHTML:str];
}
- (NSString )flattenHTML:(NSString )html {
NSScanner theScanner;
NSString text = nil;
theScanner = [NSScanner scannerWithString:html];
while ([theScanner isAtEnd] == NO) {
// find start of tag
[theScanner scanUpToString:@"<" intoString:NULL] ;
// find end of tag
[theScanner scanUpToString:@">" intoString:&text] ;
// replace the found tag with a space
//(you can filter multi-spaces out later if you wish)
html = [html stringByReplacingOccurrencesOfString:
[NSString stringWithFormat:@"%@>", text]
withString:@""];
} // while //
NSLog(@"-----===%@",html);
return html;
}
做一个查询的功能 可以根据id查到text 或者根据text查到id
附上数组如下
resultset: [{id:1,text:"aaa"},{id:2,text:"bbb"}, {id: 3,text: 'ccc'}, {id: 4,text: 'f'}]
之前尝试了一些方法 就像在传统语言那样遍历数组然后寻找相等的值 但是发现好像并不是特别好使
var resultSet =thisdataresultset
const length = resultSetlength var val = thisdatainputValue if(val){
consolelog(val) for(let i =0;i<=length;i++){ //consolelog(resultSet[i])
if(val == resultSet[i]id){
consolelo("找到了") var result = thisdataresultSet[i]id
consolelog("结果是"+result)
} else{
consolelog("没找到结果")
}
}
} else{
consolelog("没输入啊")
}
}
以上就是关于小程序 splice 二维数组全部的内容,包括:小程序 splice 二维数组、小程序 setData 的详解、小程序开发怎么过滤掉json中的html标签等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)