- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是 Function that generates multiple dynamic ID's with a defined pattern 的双胞胎帖子.
这样做的原因是我正在创建一个我应该在其中使用 Vue.js 的应用程序。我正在学习,第一个问题的解决方案中的语法非常接近它在 Vue 模板中的外观,我决定尝试重新编码。
完成的 Vue 组件应该像这样工作 jsFiddle (来自@DeepuReghunath)。我如何实现这一目标? ID 必须是动态的,单选按钮名称也是如此!
我在执行此操作时遇到的一个问题是生成新 div 的“添加问题”按钮无法按预期工作。可以看到,同一个类中既有javaScript,也有Vue。我知道这不是最终的,但由于我无法使用 Vue 隐藏和显示根组件,因此没有什么可做的。
在这里你可以看到 jsFiddle使用与下面相同的代码!
HTML
<div id="singleQuestionModule">
<form class="form-group">
<div class="d-flex justify-content-center">
<fieldset class=" form-group row">
<div id="testContainer">
<testcomponent></testcomponent>
</div>
</fieldset>
</div>
</form>
</div>
Vue.js + JavaScript
let name = 1;
let theTitle;
function testDetails() {
theTitle = document.getElementById("titleInput").value;
document.getElementById("testH1").innerHTML = theTitle;
document.getElementById("titleLabel").innerHTML = "Do you want to change the title?";
$("#removableText").hide();
$("#singleQuestionModule").show();
$("#tCreateTest").css('height', '50vh');
let aQuestion = document.getElementById('addQuestion');
if (aQuestion.style.display ==
= 'none') {
aQuestion.style.display = 'block';
}
}
Vue.component('testcomponent', {
template: `
<div>
<form class="form-group">
<div class="d-flex justify-content-center">
<fieldset class=" form-group row">
<span class="module">
<div class="input-group input-group">
<label id="wQuestionLabel" class="form-control-label" for="wQuestion">Question:</label>
</div>
<div class="form-group row">
<div class="input-group input-group">
<!-- The Question Inputfield that needs ID-->
<input type="text" class="form-control" :id="testTitle + 'Q' + name" style="width: 540px;">
</div>
</div>
<div class="form-group row">
<div class="input-group input-group">
<label id="questionOptions" class="form-control-label"
for="wQuestion">Enter avaible options:</label>
</div>
</div>
<!-- The radiobuttons and option inputfields that needs ID's-->
<div class="form-group row">
<div class="input-group input-group">
<span class="input-group-addon">
<input type="radio" :name="testTitle + 'rg' + name" :id="testTitle + 'Q' + name + 'Q'" value="1" aria-label="">
</span>
<input type="text" :id="testTitle + 'Q' + name + 'input' + '4'" class="form-control" aria-label="" style="width: 540px;"> </div>
</div>
<div class="form-group row">
<div class="input-group input-group">
<span class="input-group-addon">
<input type="radio" :name="testTitle + 'rg' + name" :id="testTitle + 'Q' + name + 'Q'" value="2" aria-label="">
</span>
<input type="text" :id="testTitle + 'Q' + name + 'input' + '4'" class="form-control" aria-label="" style="width: 540px;"> </div>
</div>
<div class="form-group row">
<div class="input-group input-group">
<span class="input-group-addon">
<input type="radio" :name="testTitle + 'rg' + name" :id="testTitle + 'Q' + name + 'Q'" value="3" aria-label="">
</span>
<input type="text" :id="testTitle + 'Q' + name + 'input' + '4'" class="form-control" aria-label="" style="width: 540px;"> </div>
</div>
<div class="form-group row">
<div class="input-group input-group">
<span class="input-group-addon">
<input type="radio" :name="testTitle + 'rg' + name" :id="testTitle + 'Q' + name + 'Q'" value="4" aria-label="">
</span>
<input type="text" :id="testTitle + 'Q' + name + 'input' + '4'" class="form-control" aria-label="" style="width: 540px;">
</div>
</div>
</span>
<span class="options-label"></span>
<br>
<div class="form-group row">
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-success" id="radioAddQuestion">
<input type="radio" @click="name++" name="options" autocomplete="off">Add
Question</label>
<label class="btn btn-success">
<input type="radio" name="options" id="radioSaveTest" value="saveTest()" autocomplete="off">Save
Test </label>
</div>
</div>
</fieldset>
</div>
</form>
</div>
`,
data: function() {
return {
name: name,
testTitle: theTitle,
}
}
});
new Vue({
el: '#testContainer',
data: {
seen: true
},
});
最佳答案
对模板和vue 对象进行了一些更改。我这边额外添加了变量 dynamicID
、count
和 addElement()
方法来实现这一点。
data: function() {
return {
testTitle: "onlineexam",
input: "input",
rg: "rg",
Q: "Q",
O: "O",
one: "1",
two: "2",
three: "3",
four: "4",
name:dynamicID
}
}});
new Vue({
el: '#testContainer',
data: {
seen: true,
count:1
},
methods: {
addElement: function () {
dynamicID++;
this.count++;
}}
});
Jsfiddle:https://jsfiddle.net/d60j70j6/
现在问题编号和问题输入字段 id 是动态生成的,具有不同的值。
关于javascript - Vue.js : How to generare multiple dynamic ID's with a defined pattern,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49776146/
如何将多个json对象添加/映射到dart对象 import 'dart:async'; import 'dart:convert'; import 'package:flutter/foundati
我正在研究将产品集成到 Dynamics Great Plains 中。我之前使用过 Dynamics CRM,但没有使用过 Great Plains。我听说 GP 与 CRM 是不同的动物,即使它们
System.Linq.Dynamic.Core 和 System.Linq.Dynamic 有什么区别?我目前正在使用 System.Linq.Dynamic 并且它不包含对 的支持选择 和 多选
我正在尝试通过Firebase存储将图像上传到Firebase,然后在Firestore中创建一个文档,其中包含上述上传图像的网址。为此,我使用此功能 void uploadImageAndCr
我一直在尝试整理一些东西,使我可以从 ListPlot 中提取点,以便在进一步的计算中使用它们。我目前的方法是使用 Locator[] 选择点。这适用于显示点,但我无法弄清楚如何从带有 head Dy
只要我在与 Program 类相同的程序集中有类 ClassSameAssembly ,下面的代码就可以正常工作。但是,当我将类 ClassSameAssembly 移动到单独的程序集时,会引发 Ru
我只是尝试从Firebase实时数据库解析数据。 但在转换为模型时有问题 我正在尝试从Flutter上解析Firebase数据库中的数据。 但是一个错误说 MY Complete QUIZ: {-M5
我创建了一个方法,当我构建它时,出现了这个错误: type '_InternalLinkedHashMap' is not a subtype of type 'List' in type cast
我对这个 flutter 的简单图表代码有疑问。在我尝试运行代码时显示此错误。请任何人都可以帮助我在这.... The argument type 'List>' can't be assigned
我尝试在我的 flutter 应用程序中解析来自 Firestore 的文档。 Firestore 文档: 我创建了两个类来解析这个文档。 类产品: class Produkt{ String n
我有一个2d-List,其中包含一个字符串和一个Map,如下所示: List> content = [ [ "String", { "one": 23,
我使用 Dart“json_serializable”包在 Flutter 应用程序中的 Firestore 数据结构下反序列化。 { googleBookId: jjl4BgAAQBAJ, prov
我注册了 Dynamic CRM 在线试用版(30 天)并创建了一个非托管自定义解决方案(新字段、一些自定义实体等)。现在,我想导出非托管解决方案并将其导入到我的服务器中的 Dynamic CRM O
当我尝试从 StreamTransform 获取一些数据时遇到一些问题 我不明白什么是正确的数据类型 未捕获的异常:类型错误:“_StreamHandlerTransformer”的实例:“_Stre
我正在尝试获取用户数据,但在这样做时出现以下错误: Exception: type '_InternalLinkedHashMap' is not a subtype of type 'Map 我查看
我正在尝试在 sqflite 数据库中保存一些带有 flutter 的数据,但我仍然收到一条错误消息: [ERROR:flutter/shell/common/shell.cc(181)] Dart
我有一个JSON响应,结构如下:。在这个JSON响应中,有各种动态键,如“Owner”和“Master”,每个键都包含一个JSON对象或一个JSON对象数组。我需要创建一个gson数据类来解析这个动态
在 Dynamics 2012 ax 中编译 CIL 时,我看到以下错误 - 名称为“Dynamics.Ax.application”的重复类型。在程序集中“Dynamics.Ax.applicati
我有一个带有 LinkedHashMap 成员的 StatefulWidget 小部件,如下所示: LinkedHashMap _items = new LinkedHashMap>(); 现在我需要
我正在尝试按照此处所述实现搜索资源功能:https://cloudblogs.microsoft.com/dynamics365/it/2019/05/21/retrieve-resource-ava
我是一名优秀的程序员,十分优秀!