function方法中数组传参的问题(小白求解决)

qq_32951937 2017-09-26 05:04:59
function next(){
var str="46ecc0c0-4616-434d-9084-8e354fc34e63,5d06a3f0-e285-4982-acfd-d0602dba1f27".split(",");
var id=GetQueryString("id");
//size()
for(var i=0;i<str.length;i++){
if(id==str[i]){
index=i;
}
}
// alert(index);
if((index+1)>str.length){
index=str.length-1;

}else{
index=index+1;
}
//跳转


在该function方法中实现翻页功能,以数组中ID为索引。小白一名,不懂数组在这要怎么表示,按推测应该直接放数组名就行,但是不加引号的情况出错如下:(错误举例)


请问大神们在
  var str=xxx.split(",");
中应用什么格式表示数组。
因为我想取的值是String值的ID,以下代码中我都取不出来是哪个地方有错。
public class Feedback implements java.io.Serializable {

private static final long serialVersionUID = 1L;

private String id;

private String title;

private String category;

private String status;

private String createUserId;

private String createUserName;

private Long reading;

private Date createDate;

private String lastModifyUserId;

private String lastModifyUserName;

private Date lastModifyDate;

private String docText;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id == null ? null : id.trim();
}


<insert id="insert" parameterType="com.huacainfo.ace.weui.model.Feedback">
insert into feedback (id, title, category,
status, createUserId, createUserName,
reading, createDate, lastModifyUserId,
lastModifyUserName, lastModifyDate, docText
)
values (#{id,jdbcType=VARCHAR}, #{title,jdbcType=VARCHAR}, #{category,jdbcType=VARCHAR},
#{status,jdbcType=CHAR}, #{createUserId,jdbcType=VARCHAR}, #{createUserName,jdbcType=VARCHAR},
#{reading,jdbcType=BIGINT}, #{createDate,jdbcType=TIMESTAMP}, #{lastModifyUserId,jdbcType=VARCHAR},
#{lastModifyUserName,jdbcType=VARCHAR}, #{lastModifyDate,jdbcType=TIMESTAMP}, #{docText,jdbcType=LONGVARCHAR}
)
</insert>


 <select id="query" resultType="map">
select t.id,t.name,t.image,a.name author,DATE_FORMAT(t.dateOfPublication, '%Y-%m-%d') dateOfPublication,
b.name category,ifnull(t.reading,0) reading
from writing t
left join writer a on t.author=a.id
left join ( SELECT
CODE,
NAME
FROM
portal.dict
WHERE
category_id = '84') b on t.category=b.code

where t.status='1'
<if test='condition.name!=null and condition.name!=""'>
and t.name like
concat('%',#{condition.name,jdbcType=VARCHAR},'%')
</if>
<if test="condition.category!=null and condition.category!=""">
and t.category =#{condition.category,jdbcType=VARCHAR}
</if>
<if test="condition.author!=null and condition.author!=""">
and t.author =#{condition.author,jdbcType=VARCHAR}
</if>
ORDER BY t.dateOfPublication desc
limit #{start,jdbcType=DECIMAL}, #{limit,jdbcType=DECIMAL}
</select>


问题不难,对于小白是一个概念性的难题。麻烦哪位大神闲暇之余看到点拨一番!
...全文
696 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
jac-song 2017-09-27
  • 打赏
  • 举报
回复
jac-song 2017-09-27
  • 打赏
  • 举报
回复
split()是字符串的方法,意思是将字符串以指定分隔符分割成数组。改方法的返回值就是数组。数组可以通过索引取值。 举个例子:

var tempStr='aa,bb,cc,dd';
var tempArray=tempStr.split(',');//以逗号进行分割
console.log(tempArray);            // 输出[aa,bb,cc,dd]
console.log(tempArray[0]);        //输出第一项aa
别闹腰不好 2017-09-27
  • 打赏
  • 举报
回复
js 中不能直接调用后台java 方法 ,你可以用 ajax 或者dwr调用。 也可将数据放到request 或session中在JS中使用
天际的海浪 2017-09-27
  • 打赏
  • 举报
回复

$.ajax({
	。。。。。。。。。。。
	。。。。。。。。。。。
	success: function (rst) {
		next(rst.value);//要在这里调用函数并获取数据
	}
});


function next(arr){
            var id=GetQueryString("id");
            //size()
            for(var i=0;i<arr.length;i++){
                if(id==arr[i].id){
                    index=i;
                }
            }
//            alert(index);
            if((index+1)>arr.length){
                index=arr.length-1;

            }else{
                index=index+1;
            }
            //跳转
qq_32951937 2017-09-26
  • 打赏
  • 举报
回复

调试发现数据在rst中,找到rst,写在var str后,出错一样。那么肯定就是语法的错误了。

52,797

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧