如何将动态生成的html元素表示的值数组绑定到模型的成员? [英] How can I bind an array of values represented by dynamically-generated html elements to the member of a model?

查看:140
本文介绍了如何将动态生成的html元素表示的值数组绑定到模型的成员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理的页面通过在cshtml页面添加时将html元素绑定到相关模型:



@model TLDReporter.Models。 PlatypusCriteriaModel



...然后,在html中,使用元素的name属性绑定到模型成员,例如BeginDate,如下所示:



< input id =BeginDatename =BeginDate/>



但是,我需要将一个项目列表存储在一个模型成员中,这是一个通用的字符串列表,我向用户提供选择条件的小部件是一个由jQuery UI手风琴小部件托管的jQuery插件。所以,我不能只用名称属性绑定它,我不认为。 IOW,我不认为添加:



name =ListDepts



里面#depts div会帮助我。



这是希望阐明环境的代码:



HTML



 <   div     id   =  accordion >  
< h3 id = deptHeader > 部门(已选择:< span > 所有< / span > < / h3 >
< div id = depts class = checkboxGroups5Col >
< / div >
< h3 id = sitesHeader > 网站(已选择: < span > 所有< / span > < / h3 >
< span class =code-keyword>< div id = sites class = checkboxGroups3Col >
< / div >
< / div >





jQuery



  var  deptsArray = []; 
for var i = 2 ; i< 100 ; i ++){
deptsArray.push(i);
}

$(' #accordion')。accordion ();
$(' #depts')。appendAllCheck()。appendCheckboxes( deptsCheckboxList',deptsArray,{
checked: true
});





(上面的appendAllCheck()和appendCheckboxes()在自定义中jQuery插件)。



我真正需要绑定到模型成员(ListDepts)就像deptsListCSV这里:



 deptsList = $(' #depts')checkedBoxes(); 
deptsListCSV = deptsList.join( );





有没有人有这种情况的经验,愿意让我知道?

解决方案

' #accordion')。accordion();


' #depts')。appendAllCheck()。appendCheckboxes(' deptsCheckboxList',deptsArray,{
checked: true
});





(上面的appendAllCheck()和appendCheckboxes()在自定义的jQuery插件中。) br />


我真正需要绑定到模型成员(ListDepts)就像deptsListCSV这样:



 deptsList =  

' #depts')。checkedBoxes();
deptsListCSV = deptsList.join( );





有没有人有这种情况的经验,愿意让我知道?


The page I'm working on binds html elements to a related model by adding this at the time of the cshtml page:

@model TLDReporter.Models.PlatypusCriteriaModel

...and then, in the html, uses the elements' name attribute to bind to model members, such as "BeginDate" like so:

<input id="BeginDate" name="BeginDate" />

However, I need to store a list of items in one of the model members, which is a generic list of string, and the widget I'm presenting the user to select the criteria is a jQuery plugin that is hosted by a jQuery UI accordion widget. So, I can't just bind to it with a name property, I don't think. IOW, I don't think adding:

name="ListDepts"

inside the #depts div will help me out.

Here's the code which hopefully elucidates the milieu:

HTML

<div id="accordion">
        <h3 id="deptHeader">Departments (selected: <span>all</span>)</h3>
        <div id="depts" class="checkboxGroups5Col">
        </div>
        <h3 id="sitesHeader">Sites (selected: <span>all</span>)</h3>
        <div id="sites" class="checkboxGroups3Col">
       </div>
    </div>



jQuery

var deptsArray = [];
    for (var i = 2; i < 100; i++) {
        deptsArray.push(i);
    }

        $('#accordion').accordion();
        $('#depts').appendAllCheck().appendCheckboxes('deptsCheckboxList', deptsArray, {
             checked: true
        });



(the "appendAllCheck()" and "appendCheckboxes()" above are in a custom jQuery plugin).

What I really need to bind to the model member ("ListDepts") is something like deptsListCSV here:

deptsList = $('#depts').checkedBoxes();
    deptsListCSV = deptsList.join(", ");



Does anybody have experience with a scenario like this that is willing to clue me in?

解决方案

('#accordion').accordion();


('#depts').appendAllCheck().appendCheckboxes('deptsCheckboxList', deptsArray, { checked: true });



(the "appendAllCheck()" and "appendCheckboxes()" above are in a custom jQuery plugin).

What I really need to bind to the model member ("ListDepts") is something like deptsListCSV here:

deptsList =


('#depts').checkedBoxes(); deptsListCSV = deptsList.join(", ");



Does anybody have experience with a scenario like this that is willing to clue me in?


这篇关于如何将动态生成的html元素表示的值数组绑定到模型的成员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆