我有一个部分视图:
<div id="AgreementBox@(ViewData["UniqueId"])" class="agreement-box">
<span>
I read agreement
</span>
<a>
terms of usage
</a>
</div>
<script>
require([
'dojo/dom',
"dijit/form/CheckBox",
"dojo/dom-construct",
"dojo/ready"],
function (dom@(ViewData["UniqueId"]), checkbox@(ViewData["UniqueId"]), construct@(ViewData["UniqueId"]), ready@(ViewData["UniqueId"])) {
ready@(ViewData["UniqueId"])(function () {
agreecheckbox@(ViewData["UniqueId"]).placeAt(dom@(ViewData["UniqueId"]).byId("AgreementBox@(ViewData["UniqueId"])"), "first");
});
var agreecheckbox@(ViewData["UniqueId"]) = new checkbox@(ViewData["UniqueId"])(
{
id: "IAgreeToTermsOfUse@(ViewData["UniqueId"])",
name: "iagreetotermsofuse@(ViewData["UniqueId"])",
class: "i-agree-checkbox",
checked: false
});
});
</script>
我在每个表单下使用此视图(每个表单都有一个唯一的id,我用作ViewData [“UniqueId”]):
@Html.Partial("../MyPartialView", new ViewDataDictionary { { "UniqueId", "Order" } })
当此视图每页显示时,它会起作用,但当它出现更多时,则该复选框不会出现在页面上。我没有得到任何错误,在chrome调试器中代码有效!
生成输出:
<div id="AgreementBoxContact" class="agreement-box">
<span>
I read agreement
</span>
<a>
terms of usage
</a>
</div>
<script>
require([
'dojo/dom',
"dijit/form/CheckBox",
"dojo/dom-construct",
"dojo/ready"],
function (domContact, checkboxContact, constructContact, readyContact) {
readyContact(function () {
agreecheckboxContact.placeAt(domContact.byId("AgreementBoxContact"), "first");
});
var agreecheckboxContact = new checkboxContact(
{
id: "IAgreeToTermsOfUseContact",
name: "iagreetotermsofuseContact",
class: "i-agree-checkbox",
checked: false
});
});
</script>
//
//on the same html page
//
<div id="AgreementBoxOrder" class="agreement-box">
<span>
I read agreement
</span>
<a>
terms of usage
</a>
</div>
<script>
require([
'dojo/dom',
"dijit/form/CheckBox",
"dojo/dom-construct",
"dojo/ready"],
function (domOrder, checkboxOrder, constructOrder, readyOrder) {
readyOrder(function () {
agreecheckboxOrder.placeAt(domOrder.byId("AgreementBoxOrder"), "first");
});
var agreecheckboxOrder = new checkboxOrder(
{
id: "IAgreeToTermsOfUseOrder",
name: "iagreetotermsofuseOrder",
class: "i-agree-checkbox",
checked: false
});
});
</script>
请帮我找出原因!
答案 0 :(得分:0)
最后我找到了答案!我仍然不知道为什么我以前的代码没有用。我改变了一点,现在它完美无缺!
<div id="AgreementBox@(ViewData["UniqueId"])" class="agreement-box">
<span>
I read agreement
</span>
<a>
terms of usage
</a>
</div>
}
<script type='text/javascript'>
require([
'dojo/dom',
"dojo/dom-construct",
"dojo/domReady!"],
function (dom@(ViewData["UniqueId"]), Create@(ViewData["UniqueId"])) {
var checkbox@(ViewData["UniqueId"]) = Create@(ViewData["UniqueId"]).create("input", {
type: "checkbox",
id: "IAgreeToTermsOfUse@(ViewData["UniqueId"])",
name: "iagreetotermsofuse@(ViewData["UniqueId"])",
class: "i-agree-checkbox"
});
Create@(ViewData["UniqueId"]).place(checkbox@(ViewData["UniqueId"]), dom@(ViewData["UniqueId"]).byId("AgreementBox@(ViewData["UniqueId"])"), "first");
});
</script>
如果有人知道为什么我以前的代码不起作用,我很乐意得到答案!我花了将近一个星期来解决这个问题,但我仍然不知道为什么会这样!