我想查看一個數組中的每個值,看看它們中的任何一個是否包含在任何其他數組值中。 例如:使用數組來過濾一個數組Javascript
arrOne = ['a', 'b' ,'c' ];
arrTwo = ['option a', 'option c', 'option b', 'option d'];
所以我希望它循環看到arrTwo每個值有從arrOne的一個值,並刪除不要讓那些我得到:
arrFinal = ['option a', 'option c', 'option b'];
這裏我與工作代碼:
的JavaScript
function PreSaveAction() {
var Fields = ['input','select','textarea']
var ReqEmpty = 0;
var RowNum = ($('table.input-table > tbody > tr').length);
var type = [];
var typeFinal = [];
var FieldType;
var FieldTypeNum;
for(var i=0; i<=(RowNum - 1); i++){
type.push($("table.input-table > tbody > tr").eq(i).html());
};
alert(type.length);
//Where a need the filter code
//using Req as arrOne and type as arrTwo
for(var i = 0; i <= (type.length - 1); i++){
for(var ii = 0; ii <= (Fields.length - 1); ii++){
if(type[i].indexOf(Fields[ii]) == -1){
FieldType = (Fields[ii]);
break;
};
};
for(var i=0; i <= (Req.length - 1); i++){
if($('.more-options').is(':visible') && ($("" + FieldType + "[title=" +"'" + Req[i] + "'"+ "]").val() == ""))
{
ReqEmpty += 1;
};
};
};
if(ReqEmpty == 0)
{
return true;
}else if(ReqEmpty == 1){
alert("There is 1 empty required field");
return false;
}else{
alert("There are " + ReqEmpty + " empty required fields");
return false;
};
};
HTML屬泰德與SharePoint
<table border="0" cellspacing="0" width="100%" class="input-table">
<tr>
<td width="190px" valign="top" class="ms-formlabel">
<H3 class="ms-standardheader">
<nobr>Title<span class="ms-formvalidation"> *</span>
</nobr>
</H3>
</td>
<td width="400px" valign="top" class="ms-formbody">
<SharePoint:FormField runat="server" id="ff1{$Pos}" ControlMode="Edit" FieldName="Title" __designer:bind="{ddwrt:DataBind('u',concat('ff1',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Title')}"/>
<SharePoint:FieldDescription runat="server" id="ff1description{$Pos}" FieldName="Title" ControlMode="Edit"/>
</td>
</tr>
<tr>
<td width="190px" valign="top" class="ms-formlabel">
<H3 class="ms-standardheader">
<nobr>Selector<span class="ms-formvalidation"> *</span>
</nobr>
</H3>
</td>
<td width="400px" valign="top" class="ms-formbody">
<SharePoint:FormField runat="server" id="ff5{$Pos}" ControlMode="Edit" FieldName="Selector" __designer:bind="{ddwrt:DataBind('u',concat('ff5',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Selector')}"/>
<SharePoint:FieldDescription runat="server" id="ff5description{$Pos}" FieldName="Selector" ControlMode="Edit"/>
</td>
</tr>
<tr>
<td width="190px" valign="top" class="ms-formlabel">
<H3 class="ms-standardheader">
<nobr>Required Hidden 1</nobr>
</H3>
</td>
<td width="400px" valign="top" class="ms-formbody">
<SharePoint:FormField runat="server" id="ff2{$Pos}" ControlMode="Edit" FieldName="Required_x0020_Hidden_x0020_1" __designer:bind="{ddwrt:DataBind('u',concat('ff2',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Required_x0020_Hidden_x0020_1')}"/>
<SharePoint:FieldDescription runat="server" id="ff2description{$Pos}" FieldName="Required_x0020_Hidden_x0020_1" ControlMode="Edit"/>
</td>
</tr>
<tr>
<td width="190px" valign="top" class="ms-formlabel">
<H3 class="ms-standardheader">
<nobr>Required Hidden 2</nobr>
</H3>
</td>
<td width="400px" valign="top" class="ms-formbody">
<SharePoint:FormField runat="server" id="ff3{$Pos}" ControlMode="Edit" FieldName="Required_x0020_Hidden_x0020_2" __designer:bind="{ddwrt:DataBind('u',concat('ff3',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Required_x0020_Hidden_x0020_2')}"/>
<SharePoint:FieldDescription runat="server" id="ff3description{$Pos}" FieldName="Required_x0020_Hidden_x0020_2" ControlMode="Edit"/>
</td>
</tr>
<tr>
<td width="190px" valign="top" class="ms-formlabel">
<H3 class="ms-standardheader">
<nobr>Not Required Hidden 1</nobr>
</H3>
</td>
<td width="400px" valign="top" class="ms-formbody">
<SharePoint:FormField runat="server" id="ff4{$Pos}" ControlMode="Edit" FieldName="Not_x0020_Required_x0020_Hidden_" __designer:bind="{ddwrt:DataBind('u',concat('ff4',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Not_x0020_Required_x0020_Hidden_')}"/>
<SharePoint:FieldDescription runat="server" id="ff4description{$Pos}" FieldName="Not_x0020_Required_x0020_Hidden_" ControlMode="Edit"/>
</td>
</tr>
<tr>
<td width="190px" valign="top" class="ms-formlabel">
<H3 class="ms-standardheader">
<nobr>Did It Work</nobr>
</H3>
</td>
<td width="400px" valign="top" class="ms-formbody">
<SharePoint:FormField runat="server" id="ff6{$Pos}" ControlMode="Edit" FieldName="Did_x0020_It_x0020_Work" __designer:bind="{ddwrt:DataBind('u',concat('ff6',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Did_x0020_It_x0020_Work')}"/>
<SharePoint:FieldDescription runat="server" id="ff6description{$Pos}" FieldName="Did_x0020_It_x0020_Work" ControlMode="Edit"/>
</td>
</tr>
<tr id="idAttachmentsRow"><td nowrap="true" valign="top" class="ms-formlabel" width="20%"><SharePoint:FieldLabel ControlMode="Edit" FieldName="Attachments" runat="server" /></td><td valign="top" class="ms-formbody" width="80%"><SharePoint:FormField runat="server" id="AttachmentsField" ControlMode="Edit" FieldName="Attachments" __designer:bind="{ddwrt:DataBind('u','AttachmentsField','Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Attachments')}" /><script>
var elm = document.getElementById("idAttachmentsTable");
if (elm == null || elm.rows.length == 0)
document.getElementById("idAttachmentsRow").style.display='none';
</script></td></tr>
<xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">
<tr>
<td colspan="99" class="ms-vb">
<span ddwrt:amkeyfield="ID" ddwrt:amkeyvalue="ddwrt:EscapeDelims(string(@ID))" ddwrt:ammode="view"></span>
</td>
</tr>
</xsl:if>
</table>
任何幫助,將不勝感激
正是你想要在有這麼大的代碼是什麼? – Mritunjay 2014-08-27 13:54:27
這是什麼問題?你已經有了代碼。 – 2014-08-27 13:54:41
這是一個SharePoint列表表單列的自定義驗證,使一些需要。我需要查看哪些列是必需的,並且我已經在數組Req中預定義了這些列。但我需要查看哪些表單元素包含所需列的標題或數組Req中的內容 – 2014-08-27 14:00:44