开发者

Adding Elements to Arrays in Grails

开发者 https://www.devze.com 2023-03-14 22:47 出处:网络
I am new to Grails and I tried to work with an Array. I can\'t believe that I don\'t get it working, but 开发者_JAVA技巧its really like this. I researched now for an hour, but I\'m somehow too stupid!

I am new to Grails and I tried to work with an Array. I can't believe that I don't get it working, but 开发者_JAVA技巧its really like this. I researched now for an hour, but I'm somehow too stupid! ;)

I've got this class:

package com.test
class SimuCacheService {

    static transactional = false

    def questionList = []

    def getQuestionList() {
        return questionList
    }
}

From antoher class I want to access the questionList and for example simply add an element

package com.test
class SimulatorController {

    def startSimu = {

        SimuCacheService cacheService = new SimuCacheService();
        def questionList = cacheService.getQuestionList();

        params.eins.each{i->
            System.out.println(i);
            **questionList.add(i);**
        }

        System.out.println(questionList[0]);
        System.out.println(questionList[1]);
    }
}

thats not working, because "add" doesn't exist. I tried with questionList[i], this did not work either. Its so annoying, I just want to use that array! Can anybody help me please? :-)

this is not working either:

questionList[questionList.length-1] = i;

:-(


try:

package com.test
class SimuCacheService {

    static transactional = false

    List questionList = []

}

all other your code can stay the same

0

精彩评论

暂无评论...
验证码 换一张
取 消