如何更改bootstrap editable元素中的数据值?

时间:2015-05-13 20:06:12

标签: jquery twitter-bootstrap x-editable

我使用bootstrap可编辑插件允许用户编辑屏幕上的字段。其中一个字段在单击时会显示一个小弹出窗口,允许用户从下拉列表中选择下拉列表旁边的复选标记,以允许用户将值应用于该字段。我的标记有一个简单的锚点,如下所示:

<a href="#" id="primaryoption_1" data-type="select" data-name="option" data-value="0" class="editable-discreet">Split EM/SEM</a>

我的jQuery代码使用bootstrap启用此功能:

 var gaPrimaryOptions = [
    { value: 0, text: 'Split EM/SEM' },
    { value: 1, text: 'Only EM' },
    { value: 2, text: 'Only SEM' }
    ];

$("a[id^=primaryoption_][id!='primaryoption_{departmentid}']").editable({
        source: gaPrimaryOptions,
        onblur: 'submit'
    });

如果您发现我的标记有一个数据值属性,默认值为&#34; 0&#34;。

我遇到的问题是,当用户从下拉列表中选择另一个项目并单击复选标记时,如何将数据值更改为适当的值。我的数据值始终保持在&#34; 0&#34;即使用户选择了另一个项目,例如&#34;只有EM&#34;其值为&#34; 1&#34;。

1 个答案:

答案 0 :(得分:1)

如何使用浏览器中的开发工具检查值?如果是这样,我认为你不会发现你想要的价值在变化。

询问的原因是因为代码看起来很好,试试这个:

var gaPrimaryOptions = [
    { value: 0, text: 'Split EM/SEM' },
    { value: 1, text: 'Only EM' },
    { value: 2, text: 'Only SEM' }
];


$("a[id^=primaryoption_][id!='primaryoption_{departmentid}']").editable({
    source: gaPrimaryOptions,
    onblur: 'submit',
    validate: function(value) {
        console.log("You've chosen " + value);
    }, success: function(response, newValue) {
        console.log("New value is " + newValue);
    }
});

current_value = $("a[id^=primaryoption_][id!='primaryoption_{departmentid}']").editable('getValue', true);
console.log("Curent value is " + current_value);

http://jsfiddle.net/3KkZd/375/