var RadioListObj = function (id, url) {
this.URL = url;//radiobox source URL
this.ID = id;//radioList ID, radio id is ID_radio
this.method = 'get'; //ajax method
this.width = 600; //initial width
this.height = 100; //initial height
this.checkedValue = ""; //radiolist value
this.initialValue = ""; //initial value
this.valueField = "ID";
this.textField = "Name";
this.enable = true; //set the radiolist enable/disabled
this.isVertical = true; //set the radiolist's layout
}

//Set radiolist width
RadioListObj.prototype.setWidth = function (wid) { $("#" + this.ID).css("width", wid); };

//set radiolist height
RadioListObj.prototype.setHeight = function (hei) { $("#" + this.ID).css("height", hei); };

//initial radioList data and load data
RadioListObj.prototype.loadData = function () {
var context = this;
$.ajax({
url: context.URL,
type: context.method,
dataType: "json",
contentType: "application/json;charset=utf-8",
beforeSend: function () {
// add the initial loading radio before getting the source from webservice
$("#" + context.ID).append("<input type='radio' name='" + context.ID + "_radio' value='' checked='checked' />loading..");
context.checkedValue = $("[name='" + context.ID + "_radio']").val();
},
success: function (data) {
//set the initial width and height
$("#" + context.ID).css("width", context.width);
$("#" + context.ID).css("height", context.height);
var style = "";
var lineEnd = "<p/>";
context.source = data;
$("#" + context.ID).empty();
if (context.isVertical) {
style = "style='margin-top:5px;'";
} else {
style = "style='margin-right:2px;'"
lineEnd = "<label style='margin-right:10px;'/>";
}
//add the radioes to the radio list
$(data).each(function (i, item) {
var val = item[context.valueField];
var txt = item[context.textField];
$radio = $("<input type='radio' name='" + context.ID + "_radio' value='" + val + "' " + style + "/>" + txt + lineEnd);
$("#" + context.ID).append($radio);
$radio.on('change', function (evt) {
context.checkedChange($(this).val());
context.setValue($(this).val());
});
});
if (data != null && context.initValue != "") {
context.setValue(context.initialValue);
}
//initial if the radio list is editable
context.enable ? "" : context.setDisabled();
},
error: function (e) {
console.log(e);
},
headers: {
'Token': $("#_requiredToken").val()
}
});
}

// set the radio list enabled
RadioListObj.prototype.setEnabled = function () {
$("[name='" + this.ID + "_radio']").removeAttr("disabled");
}

//set the radio list disabled
RadioListObj.prototype.setDisabled = function () {
$("[name='" + this.ID + "_radio']").attr("disabled", "disabled");
}

//checked change function
RadioListObj.prototype.checkedChange = function (val) {
}

//set the radio list value
RadioListObj.prototype.setValue = function (val) {
$("[name='" + this.ID + "_radio']").removeAttr("checked");
$("[name='" + this.ID + "_radio'][value='" + val + "']").attr("checked", "checked");
this.checkedValue = val;
}

//get the radio list's selected value
RadioListObj.prototype.getValue = function () {
return this.checkedValue;
}

//This code is for radioList test
//$(function () {
// var o = new RadioListObj('ra', '/ResourceAPI/api/Resource/GetWorlds');
// o.loadData();
// //o.setDisabled();

// o.checkedChange = function (select) {
// console.log(select);
// }
// $(document).on("click", function () {
// //o.setEnabled();
// //o.setValue("23617");
// });
//});

自定义控件之 RadioList的更多相关文章

  1. android自定义控件一站式入门

    自定义控件 Android系统提供了一系列UI相关的类来帮助我们构造app的界面,以及完成交互的处理. 一般的,所有可以在窗口中被展示的UI对象类型,最终都是继承自View的类,这包括展示最终内容的非 ...

  2. ASP.NET MVC学习之母版页和自定义控件的使用

    一.母板页_Layout.cshtml类似于传统WebForm中的.master文件,起到页面整体框架重用的目地1.母板页代码预览 <!DOCTYPE html> <html> ...

  3. C# 自定义控件VS用户控件

    1 自定义控件与用户控件区别 WinForm中, 用户控件(User Control):继承自 UserControl,主要用于开发 Container 控件,Container控件可以添加其他Con ...

  4. 自定义控件之 圆形 / 圆角 ImageView

    一.问题在哪里? 问题来源于app开发中一个很常见的场景——用户头像要展示成圆的:       二.怎么搞? 机智的我,第一想法就是,切一张中间圆形透明.四周与底色相同.尺寸与头像相同的蒙板图片,盖在 ...

  5. 如何开发FineReport的自定义控件?

    FineReport作为插件化开发的报表软件,有些特殊需求的功能需要自己开发,开发的插件包帆软官方有提提供,可以去帆软论坛上找,本文将主要介绍如何开发一个自定义控件,这里讲讲方法论. 第一步:实例化一 ...

  6. WPF自定义控件第二 - 转盘按钮控件

    继之前那个控件,又做了一个原理差不多的控件.这个控件主要模仿百度贴吧WP版帖子浏览界面左下角那个弹出的按钮盘.希望对大家有帮助. 这个控件和之前的也差不多,为了不让大家白看,文章最后发干货. 由于这个 ...

  7. 【Win 10应用开发】AdaptiveTrigger在自定义控件中是可以触发的

    前些天,看到有网友给我留言,说AdaptiveTrigger在自定义控件(模板化控件)中不能触发.因为当时我正在写其他的代码,就没有去做实验来验证,于是我就给这位网友提了使用GotoVisualSta ...

  8. WPF自定义控件与样式(3)-TextBox & RichTextBox & PasswordBox样式、水印、Label标签、功能扩展

    一.前言.预览 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要是对文本 ...

  9. Android自定义控件之自定义ViewGroup实现标签云

    前言: 前面几篇讲了自定义控件绘制原理Android自定义控件之基本原理(一),自定义属性Android自定义控件之自定义属性(二),自定义组合控件Android自定义控件之自定义组合控件(三),常言 ...

随机推荐

  1. Pyhton 学习总结 20 :执行系统命令

    在Python中执行系统命令有os.system().os.popen().commands.getstatusoutput().subprocess.Popen等     1.os.system() ...

  2. HTML报表日期格式不对 导致报错ORA-01861: 文字与格式字符串不匹配

    PROCEDURE MAIN(ERRBUF OUT VARCHAR2, RETCODE OUT VARCHAR2, P_CUSTOMER_ID IN VARCHAR2, P_PERSON_ID IN ...

  3. 微信中修改title

    //需要jQuery.zepto版 function weixinTitle(){ var $body = $('body'); document.title = 'title'; // hack在微 ...

  4. Spark实战4:异常检测算法Scala语言

    异常检测原理是根据训练数据的高斯分布,计算均值和方差,若测试数据样本点带入高斯公式计算的概率低于某个阈值(0.1),判定为异常点. 1 创建数据集转化工具类,把csv数据集转化为RDD数据结构 imp ...

  5. fgets函数

    打开文件 fopen("需要打开的路径") 然后使用fgets函数读取行 #include <stdio.h> #include <stdlib.h> #i ...

  6. Python3基础 not in列表名 判断一个元素是否不在列表中列表中

    镇场诗:---大梦谁觉,水月中建博客.百千磨难,才知世事无常.---今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ ...

  7. 3. Swift 数组|字典|集合

    在OC中数组,字典,集合有自己的表示方法,分别是Array,Dictionary,Set 与 String 都属于数值类型变量,他们都属于结构体. 使用简介灵活多变,个人感觉可读性变差了很多,用起来由 ...

  8. faster alter table add column

    Create a new table (using the structure of the current table) with the new column(s) included. execu ...

  9. How to install .deb file in Ubuntu

    if you have a .deb file: You can install it using sudo dpkg -i /path/to/deb/file followed by sudo ap ...

  10. SpringBoot集成jsp(附源码)+遇到的坑

    1.大体步骤 (1)       创建Maven web project: (2)       在pom.xml文件添加依赖: (3)       配置application.properties支持 ...