【发布时间】:2011-06-05 08:46:06
【问题描述】:
我有 2 个模式形式的无线电组。我很难弄清楚如何从 json 字符串中为每个组设置值。json 字符串中的最后 2 个值是“角色”和“活性”。激活是 1 表示是或 0 现在。管理员、员工或用户的角色为 1、2 或 3。我遍历 json 字符串并将值分配给字段名称,因为它们在 html 中都是相同的。
我的html是:
<div class="form-field bt-space10">
<div class="clear">
<h4 class="fl-space2 ln-22 size-120" style="color:#777777; font-size: 12px; font-weight: normal;">Authorization Role: </h4>
<div class="form-radio-item clear fl-space2">
<input type="radio" rel="radiogroup" name="role" id="Admin" value="1" class="radio fl-space" /> <label for="Admin" class="fl">Admin</label>
</div>
<div class="form-radio-item clear fl-space2">
<input type="radio" rel="radiogroup" name="role" id="Staff" value="2" class="radio fl-space" /> <label for="Staff" class="fl">Staff</label>
</div>
<div class="form-radio-item clear fl-space2">
<input type="radio" rel="radiogroup" name="role" id="User" value="3" class="radio fl-space" /> <label for="User" class="fl">User</label>
</div>
</div>
<div class="clear">
<h4 class="fl-space2 ln-22 size-120" style="color:#777777; font-size: 12px; font-weight: normal;">Account Activated: </h4>
<div class="form-radio-item clear fl-space2">
<input type="radio" rel="radiogroup1" name="activated" id="Yes" class="radio fl-space" /> <label for="radio4" class="fl">Yes</label>
</div>
<div class="form-radio-item clear fl-space2">
<input type="radio" rel="radiogroup1" name="activated" id="No" class="radio fl-space" /> <label for="radio5" class="fl">No</label>
</div>
</div>
</div><!-- /.form-field-->
我传入的 json 字符串(如果需要,我可以将返回更改为“Role”:“Admin”等。和“activated”:“Yes”等):
{"op": "UPDATE", "id": "7","email": "joe@public.com","name": "Joe Public","address": "123 Any Street","city": "AnyTown","zipcode": "12345","state": "PA","contact_name": "","phone": "8885551212","fax": "","company_branch": "","company_name": "","activated": "1","role": "1" }
我用来填充表单上其他字段的代码:
function editUser(rowID, callback) {
var ret;
jQuery.fancybox({
modal : true,
padding : 0,
cache : false,
overlayOpacity : 0.5,
href : "userEdit.html",
onComplete : function() {
InitProfileMenu()
var tsTimeStamp= new Date().getTime();
$.getJSON("includes/GetUserDetails.php?tsTimeStamp&id=" + rowID,
function(data) {
$.each(data, function(i, item) {
$('#' + i).val(item);
});
})
jQuery("#editUser_cancel").click(function() {
ret = false;
jQuery.fancybox.close();
})
jQuery("#editUser_ok").click(function() {
jQuery.fancybox.close();
ret = true;
})
},
我已经用谷歌搜索死了,但没有找到解决方案。谁有想法?或者他们可以指出我的资源,这将有助于解决这个问题?
【问题讨论】:
标签: javascript jquery jquery-events getjson