在javascript中添加数组对象并删除数组对象?

时间:2012-03-22 15:13:56

标签: javascript jquery arrays

我想删除数组中的一个对象,并将新对象添加到数组中。任何人都可以解决这个问题吗?

Default.aspx的:

<div data-role="content">
        <div>
            <div id="addNewDocumentRelationShip" data-inline="true" style="float:left" data-role="button" class="ui-btn-left" rel="external" data-theme="b">Add New Item</div>
            <div id="removeDocumentRelationShip" data-inline="true" style="float:right" data-role="button" class="ui-btn-right" rel="external" data-theme="b">Remove</div>
        </div>
        <div id="lookupItemsDisplayList">            
        </div>
</div>

constant.js:

var constants.constLookupArray = [{
"Item":"2"
"Display":"jQuery"
},
{
"Item":"2"
"Display":"jQuery"
},
{
"Item":"2"
"Display":"jQuery"
},
{
"Item":"2"
"Display":"jQuery"
}];

edit.js:

var lookupDiv = document.getElementById('lookupItemsDisplayList');

$(lookupDiv).html("");

// create new div that will work as a container
var newlookupDiv = $('<div></div>').attr('data-role', 'fieldcontain'); 

var fieldset = $('<fieldset></fieldset>').attr('data-role', 'controlgroup');

var checkBox = constants.EMPTY_STRING;

for (var item in lookupsArray) {
            checkBox = checkBox + "<input type='checkbox' data-theme='b' id='" + lookupsArray[item].Item + "' name='check' value='" + lookupsArray[item].DisplayValue + "'><label for='" + lookupsArray[item].Item + "' data-iconpos='right'>" + lookupsArray[item].DisplayValue + "</label>";
        }

   fieldset.html(checkBox);
   newlookupDiv.html(fieldset);
   $(lookupDiv).html(newlookupDiv);
   $(lookupDiv).trigger('create');

0 个答案:

没有答案