有没有办法动态修改colModel中status字段的值?
假设我们有一个col模型,其字段如下:
... field ... name: "state",type: "select",
editoptions: {value: "0:state0;1:state1;2:state2;3:state3;4:state4"}
所以我得到了一个有这个值的状态选择字段。但我需要动态地决定哪些selectfields是可能的。
如果当前行的状态为state0,则只应显示state0和state1。
如果状态为state1,则显示应为state0、state1和state2
我是否可以用格式化程序来解决这个问题,或者是否有其他方法来做这样的事情。
更困难的是,假设在我的应用程序中显示的状态通常依赖于登录的用户。
在某种程度上,用户只能看到state0、state2和state4。
这可能会变得更加复杂,因为当前用户不允许在state3和state4之间进行转换。
然而,状态本身也是动态的。为我的应用程序中的一个对象动态生成javascript(它表示一个通用的state类)并使用这个对象在格式化程序中生成我需要的输出,会有帮助吗?
所以我可以将逻辑封装在这个对象中,如何生成输出,另外我只得到用户能够看到的状态。
应该让我一举两得。
具体问题的解决方案,thx到oleg:
editoptions : {
value : function(){
//a function can be called here:
currentRow=$("#order_items").getGridParam('selrow');
currentState=$("#order_items").getCell(currentRow,"state");
nastyGeneratedThings=function(){
... do some nasty things with currentState
... and generate what you want
}
return nastyGeneratedThings
}
我遇到了一些麻烦,因为函数只调用了一次。所以我必须在Navgrid中设置recreateForm选项。
navGrid("#pager", {
edit : true,
add : true,
del : true
}, {
height : 500,
width : 500,
// recreate the form every time when edit button is clicked.
// Default is false.
recreateForm : true
}
});
之后,每次单击“编辑”时,我的函数都会激发。
希望这能帮上忙。