有没有办法动态修改 colModel 中状态字段的值?假设我们有一个 col 模型,其字段如下:
... field ... name: "state",type: "select",
editoptions: {value: "0:state0;1:state1;2:state2;3:state3;4:state4"}
所以我得到一个带有这个值的状态的选择字段。但我需要动态决定哪些选择字段应该是可能的。如果当前行的状态为 state0,则只显示 state0 和 state1。如果 state 是 state1,则显示应该是 state0、state1 和 state2,依此类推,直到 state 4,它应该只显示 stae3 和 state4。
我能用格式化程序解决这个问题,还是有其他方法可以做到这一点。
为了使它更困难,假设通常显示的状态取决于在我的应用程序中登录的用户。在某种程度上,用户只能看到 state0、state2 和 state4。这可能会变得更加复杂,因为当前用户不允许 state3 和 state4 之间的转换。
然而,状态本身也是动态的。为我的应用程序中的对象动态生成 javascript 是否有帮助,该对象代表一般状态类并使用此对象在格式化程序中生成我需要的输出?所以我可以封装这个对象中的逻辑,我的输出是如何生成的,另外我只得到用户能够看到的状态。
应该让我用一块石头杀死两只鸟。
重读后我希望它清楚我想做什么,如果没有告诉我,我会更详细地解释它。
具体问题的解决方案,感谢 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
}
});
之后,每次单击编辑时都会触发我的功能。希望这对某人有所帮助。