Как ограничить поиск jquery с помощью селекторов? - PullRequest
0 голосов
/ 11 октября 2018

Я хочу ограничить то, что возвращается из следующего кода.У меня есть это, которое возвращает всех родителей, которые являются ул.т.е. в основном все UL в моем дереве, но я хочу только UL в текущей ветви.Обсуждаемая ветвь отмечена зеленым на изображении.Итак, не остальные основные ветки под рутом (Admin).(например, не ветки для контактов, безопасности и т. д.)

Tree image

т.е. Admin -> Users -> new subby tst3 -> Read

Как бы я это сделал?

var parentEls = $(this).parents("ul").find("input[type=checkbox]")

разметка

<li>
	<span class="accordion-heading" aria-expanded="true" data-toggle="collapse" data-target="#MMID_0">
		<span class="checkbox MMTree-checkbox styled red"><input name="MM_0" class="MMTree-checkbox styled red" id="MM_0" style="display: none;" type="checkbox" value="false" iid="0"></span>
		Admin
	</span>
	<ul class="nav nav-list collapse in" id="MMID_0" aria-expanded="true" style="padding-left: 20px;">
		<li>
			<span class="accordion-heading" aria-expanded="false" data-toggle="collapse" data-target="#submenu_0_0">
				<span class="checkbox subtree-checkbox styled red"><input name="SM_0_0" class="subtree-checkbox styled red" id="SM_0_0" style="display: none;" type="checkbox" value="false" iid="1"></span>
				Debtors-Creditors
			</span>
			<ul class="nav nav-list collapse" id="submenu_0_0" aria-expanded="true" style="padding-left: 20px;">
				<li>
					<span class="accordion-heading" aria-expanded="true" data-toggle="collapse" data-target="#submenu_0_0SM_0_00">
						<span class="checkbox subtree-checkbox styled red"><input name="Pr_SM_0_00" class="subtree-checkbox styled red" id="Pr_SM_0_00" style="display: none;" type="checkbox" value="false" iid="0"></span>
						Read
					</span>
				</li>
				<li>
					<span class="accordion-heading" aria-expanded="true" data-toggle="collapse" data-target="#submenu_0_0SM_0_10">
						<span class="checkbox subtree-checkbox styled red"><input name="Pr_SM_0_10" class="subtree-checkbox styled red" id="Pr_SM_0_10" style="display: none;" type="checkbox" value="false" iid="0"></span>
						Create
					</span>
				</li>
				<li>
					<span class="accordion-heading" aria-expanded="true" data-toggle="collapse" data-target="#submenu_0_0SM_0_20">
						<span class="checkbox subtree-checkbox styled red"><input name="Pr_SM_0_20" class="subtree-checkbox styled red" id="Pr_SM_0_20" style="display: none;" type="checkbox" value="false" iid="0"></span>
						Update
					</span>
				</li>
				<li>
					<span class="accordion-heading" aria-expanded="true" data-toggle="collapse" data-target="#submenu_0_0SM_0_30">
						<span class="checkbox subtree-checkbox styled red"><input name="Pr_SM_0_30" class="subtree-checkbox styled red" id="Pr_SM_0_30" style="display: none;" type="checkbox" value="false" iid="0"></span>
						Delete
					</span>
				</li>
			</ul>

		</li>
		<li>
			<span class="accordion-heading" aria-expanded="true" data-toggle="collapse" data-target="#Smenu_0_1__1">
				<span class="checkbox subtree-checkbox styled red"><input name="SM_0_1" class="subtree-checkbox styled red" id="SM_0_1" style="display: none;" type="checkbox" value="false" iid="1"></span>
				Users
			</span>
			<ul class="nav nav-list collapse in" id="Smenu_0_1__1" aria-expanded="true" style="padding-left: 60px;">
				<li>
					<span class="accordion-heading" aria-expanded="true" data-toggle="collapse" data-target="#Smenu_0_1__10">
						<span class="checkbox subtree-checkbox styled red"><input name="SM_0_1_1" class="subtree-checkbox styled red" id="SM_0_1_1" style="display: none;" type="checkbox" value="false" iid="2"></span>
						new subby tst3
					</span>
					<ul class="nav nav-list collapse in" id="Smenu_0_1__10" aria-expanded="true" style="padding-left: 20px;">
						<li>
							<span class="accordion-heading" aria-expanded="true" data-toggle="collapse" data-target="#Smenu_0_1__10SM_0_1_1_00">
								<span class="checkbox subtree-checkbox styled green checked"><input name="Pr_SM_0_1_1_00" class="subtree-checkbox styled red" id="Pr_SM_0_1_1_00" style="display: none;" type="checkbox" value="false" iid="0"></span>
								Read
							</span>
						</li>
						<li>
							<span class="accordion-heading" aria-expanded="true" data-toggle="collapse" data-target="#Smenu_0_1__10SM_0_1_1_10">
								<span class="checkbox subtree-checkbox styled red"><input name="Pr_SM_0_1_1_10" class="subtree-checkbox styled red" id="Pr_SM_0_1_1_10" style="display: none;" type="checkbox" value="false" iid="0"></span>
								Create
							</span>
						</li>
						<li>
							<span class="accordion-heading" aria-expanded="true" data-toggle="collapse" data-target="#Smenu_0_1__10SM_0_1_1_20">
								<span class="checkbox subtree-checkbox styled red"><input name="Pr_SM_0_1_1_20" class="subtree-checkbox styled red" id="Pr_SM_0_1_1_20" style="display: none;" type="checkbox" value="false" iid="0"></span>
								Update
							</span>
						</li>
						<li>
							<span class="accordion-heading" aria-expanded="true" data-toggle="collapse" data-target="#Smenu_0_1__10SM_0_1_1_30">
								<span class="checkbox subtree-checkbox styled red"><input name="Pr_SM_0_1_1_30" class="subtree-checkbox styled red" id="Pr_SM_0_1_1_30" style="display: none;" type="checkbox" value="false" iid="0"></span>
								Delete
							</span>
						</li>
					</ul>
				</li>
			</ul>

		</li>
		<li>
			<span class="accordion-heading" aria-expanded="false" data-toggle="collapse" data-target="#Smenu_0_1__2">
				<span class="checkbox subtree-checkbox styled red"><input name="SM_0_2" class="subtree-checkbox styled red" id="SM_0_2" style="display: none;" type="checkbox" value="false" iid="1"></span>
				Contacts
			</span>
			<ul class="nav nav-list collapse" id="Smenu_0_1__2" style="padding-left: 60px;">
				<li>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...