我目前正在使用此代码将复选框显示为自定义控件,并且它完美无缺:
// Create the checkbox and add it to the DOM.
var checkbox = $("<input type='checkbox'/>")
.css({
height: 20,
width: 20,
margin: "10px"
})
.appendTo($(element));
// Determine if the change was initiated by the user.
var changingValue = false;
checkbox.change(function () {
changingValue = true;
contentItem.value = checkbox[0].checked;
changingValue = false;
});
contentItem.dataBind("value", function (newValue) {
if (!changingValue) {
checkbox[0].checked = newValue;
}
});
然而现在我想扩展一点,我想知道是否有人知道我如何根据它们是真还是假来计算值。
我在寻找什么: 我有2个复选框, 1st 是&#34; TRUE &#34;而第二是&#34; FALSE &#34;
window.alert("add in text here" + add_code_here)
< / LI>
所以示例数据将是:
var trueCount = 0;
var falseCount = 0;
window.alert("There are: " + trueCount + " values that are true and " + falseCount + " that are false");
以及上面的示例trueCount = 1
和falseCount = 1
感谢您提供给我的任何意见,非常感谢
答案 0 :(得分:0)
我无法使用自定义控件复选框,但对于标准开关,此代码适用于我:
var trueCount = 0;
var falseCount = 0;
myapp.TableName.ColumnName_postRender = function(element,contentItem){ //计算真值或假值 contentItem.dataBind(“value”,function(newValue){
if (contentItem.value == true) { trueCount ++; falseCount--; } else if (contentItem.value == false) { falseCount++; trueCount--; } }); //count 3 sets both trueCount and falseCount to 0 as they would already be affected by the //post render method. This works by adding or subtracting the amount of false values non //screen (works my my scenario) var count3 = 0; if (contentItem.value == false) { count3++; } falseCount = falseCount - count3; trueCount = trueCount + count3;
};
myapp.TableName.Save_execute = function (screen) {
window.alert("True Count: " + trueCount + " | falseCount: " + falseCount);
//set both count values back to 0 for when the screen is next run
trueCount = 0;
falseCount = 0;
}