要求: 我如何转换以下 json 格式。
从 :
[
{"u0":{"user_id":"124", "name":"Eloise R. Morton"}},
{"u1":{"user_id":"126", "name":"Mary S. Williams"}}
]
Run Code Online (Sandbox Code Playgroud)
到 :
{
"u0":{"user_id":"124", "name":"Eloise R. Morton"},
"u1":{"user_id":"126", "name":"Mary S. Williams"}
}
Run Code Online (Sandbox Code Playgroud)
我想从 JSON 中删除/删除第一个和最后一个方括号。
PHP代码:
$sql = "SELECT * FROM user_list";
$result = $conn->query($sql);
$user_count=0;
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$user_count_id="u".$user_count;
$user_count++;
$user_list[]= array($user_count_id=>$row);
}
} else {
echo "0 results";
}
echo json_encode($user_list);
$conn->close();
Run Code Online (Sandbox Code Playgroud)
Javascript代码:
function update_user_list(){
//Fetch data
$.ajax( "user_list.php" ).done(function(json) …
Run Code Online (Sandbox Code Playgroud) 我搜索过高和低,无法找到任何脚本或说明如何ONLY ONCE
在最初加载/查看后自动刷新页面.
我实现了一个javascript代码,声明:如果页面完全加载,立即刷新页面,但只刷新一次.
window.onload = function () {window.location.reload()}
Run Code Online (Sandbox Code Playgroud)
但这给出了一个没有"只有一次"的循环.
我也实现了,meta refresh
但它也给了一个循环.
<meta http-equiv="refresh" content= "0;URL=http://www.example.com" />
Run Code Online (Sandbox Code Playgroud)
请告诉我如何首次使用身体onload
刷新功能only once
,而不是每次刷新php页面时都使用.
我表达你的直接反应.谢谢
摘要:
每当我尝试使用data-slide
中HTML DOM
,我在我的js控制台中得到这个错误:
错误:[$ compile:ctreq]无法找到指令'slide'所需的控制器'carousel'!
我用bootstrap和angularjs创建了一个应用程序.我已经添加了这个库<script type="text/javascript" src="/bower_components/bootstrap/dist/js/bootstrap.js"></script>
.
我ui.bootstrap
在创建应用程序时将其作为依赖项包含在内.
整个错误:
Error: [$compile:ctreq] Controller 'carousel', required by directive 'slide', can't be found!
http://errors.angularjs.org/1.4.10/$compile/ctreq?p0=carousel&p1=slide
at angular.js:68
at getControllers (angular.js:8432)
at nodeLinkFn (angular.js:8570)
at angular.js:8810
at processQueue (angular.js:15097)
at angular.js:15113
at Scope.$eval (angular.js:16359)
at Scope.$digest (angular.js:16175)
at Scope.$apply (angular.js:16467)
at done (angular.js:10852)
Run Code Online (Sandbox Code Playgroud)
模板的相关部分:
<div id="carousel-example-generic" class="carousel" data-ride="carousel" data-interval="false">
<a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
<span class="glyphicon glyphicon-triangle-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" …
Run Code Online (Sandbox Code Playgroud) 问题陈述 :
使用类型定义变量,number
但是在将任何字符串分配到此变量中并尝试将transpile
其转换为JavaScript时.Transpiler
没有任何错误.
问题演示:
class.ts
class User {
age:number;
name:string;
phone:number | string;
constructor(a, n, p) {
this.age = a;
this.name = n;
this.phone = p;
}
getDetails() {
return "Age : " + this.age + ", Name : " + this.name + ", Phone : " + this.phone;
}
}
var firstUser = new User("27", "Rohit", "945*****44");
console.log(firstUser.getDetails());
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,我们将age
变量定义为number
但是在创建类的实例时,User
我传递的是age,"27"
即string.因此,虽然转换它应该抛出错误但它被转换成JavaScript而没有任何错误.
经过输出:
但是在相同的代码库中,如果我直接将字符串this.age
赋值给构造函数中的变量.Transpiler会抛出错误.
class.ts
class …
Run Code Online (Sandbox Code Playgroud) <v-autocomplete
v-model="friends"
:disabled="isUpdating"
:items="people"
label="Select"
item-text="name" <!-- use here Array ['name', 'id', 'value'] -->
item-value="name"
>
Run Code Online (Sandbox Code Playgroud)
可以在 Vuetify 中的“text-item”上使用属性数组吗?
我有一个正在填充的表格如下:
<table>
<tr>
<th>Id</th>
<th>Details</th>
<th>Score</th>
</tr>
<tr ng-repeat="x in data.items">
<td><a href="{{ x.get }}">{{ x.id }}</td>
<td>
<p><b>{{ x.name[0] }}</b></p>
<p><u>Brand</u>: {{ x.Brand }}; <u>Category URL</u>: {{ x.mlnURL }};<u>Price</u>: Rs {{x.Price}} </p>
</td>
<td>
<p><a href="{{x.explain}}"><b>{{ x.score }}</b></a></p>
Classifier Score: {{ x.cscore }} <br>
Document Score: {{ x.sscore }} </p>
</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
现在在这一行
<tr ng-repeat="x in data.items">
Run Code Online (Sandbox Code Playgroud)
而不是在data.items中运行所有x的敌人,我想根据用户的需要运行它有限次数.我有来自用户的这个数字输入并存储在变量中.我怎样才能做到这一点.
我有一组选项卡,显示选项卡打开的每个容器中的项目数量.您将在下面看到该过滤器.而且我想展示filtered.length
我想的内部物体的数量.
这是我的数据:
[
{
"img":"assets/images/gallery/girls-1.jpg",
"group": "girls",
"title": "Image 1",
"desc": "Description",
"link":""
},
{
"img":"assets/images/gallery/girls-2.jpg",
"group": "girls",
"title": "Image 2",
"desc": "Description",
"link":""
},
{
"img":"assets/images/gallery/girls-3.jpg",
"group": "girls",
"title": "Image 3",
"desc": "Description",
"link":""
},
{
"img":"assets/images/gallery/music-1.jpg",
"group": "music",
"title": "Image 4",
"desc": "Description",
"link":""
},
{
"img":"assets/images/gallery/music-2.jpg",
"group": "music",
"title": "Image 5",
"desc": "Description",
"link":""
},
{
"img":"assets/images/gallery/music-3.jpg",
"group": "music",
"title": "Image 6",
"desc": "Description",
"link":""
},
{
"img":"assets/images/gallery/music-4.jpg",
"group": "music",
"title": "Image 7",
"desc": "Description", …
Run Code Online (Sandbox Code Playgroud) 由于该Array.splice()
功能,v-if
即使第二个条件正确,也只会触发第一个。当我 console.log 对象时,photos
“照片”对象的数字长度会逐渐变小,4
直到0
满足第一个条件为止。如何阻止这种情况发生以显示正确的 div ?这是我的代码主体:
<div v-if="(checkCount = 1)">
<Splide :options="{ rewind: true }" aria-label="Carousel Pictures">
<SplideSlide class="fs-800">
<div v-for="item in photos.splice(0, 4)" :key="item.id">
<a href="">
<img :src="item.img" alt="" />
<p>{{ item.text }}</p>
</a>
</div>
</SplideSlide>
</Splide>
</div>
<div v-else-if="(checkCount = 2)">
<Splide :options="{ rewind: true }" aria-label="Carousel Pictures">
<SplideSlide class="fs-800">
<div v-for="item in photos.splice(0, 4)" :key="item.id">
<a href="">
<img :src="item.img" alt="" />
<p>{{ item.text }}</p>
</a>
</div>
</SplideSlide> …
Run Code Online (Sandbox Code Playgroud) 原因:
如果一个类没有提供任何,constructors
那么default constructor(constructor without parameter)
在编译时由编译器给出,但如果一个类包含,parameterized constructors
那么编译器不提供默认构造函数.
我正在编译下面的代码.它给出了编译错误.
代码:
class ConstructorTest
{
// attributes
private int l,b;
// behaviour
public void display()
{
System.out.println("length="+l);
System.out.println("breadth="+b);
}
public int area()
{
return l*b;
}
// initialization
public ConstructorTest(int x,int y) // Parameterized Constructor
{
l=x;
b=y;
}
//main method
public static void main(String arr[])
{
ConstructorTest r = new ConstructorTest(5,10);
ConstructorTest s = new ConstructorTest();
s.display();
r.display();
r.area();
}
}
Run Code Online (Sandbox Code Playgroud)
控制台错误:
当我只调用时parameterized constructor
.它的工作正常.但是当想要调用default …
javascript ×6
angularjs ×3
jquery ×3
html ×2
php ×2
vue.js ×2
autocomplete ×1
carousel ×1
class ×1
constructor ×1
if-statement ×1
java ×1
json ×1
oop ×1
page-refresh ×1
transpiler ×1
typescript ×1
ui.bootstrap ×1
v-for ×1
vuetify.js ×1