我有这样一个数组:
array(2) {
[0]=> array(1) { ["cate_id"]=> string(2) "14" }
[1]=> array(1) { ["cate_id"]=> string(2) "15" }
}
Run Code Online (Sandbox Code Playgroud)
如何在不使用for循环的情况下检查数组中是否存在值14?
我试过这段代码:
var_dump(in_array('14',$categoriesId));exit;
Run Code Online (Sandbox Code Playgroud)
但它回来了false,我不知道为什么.
首先我使用knockout js成功显示数据,这是我的代码:
JS
var viewMode = {
lookupCollection: ko.observableArray()
};
$(document).ready(function () {
$.ajax({
type: "GET",
url: "/Home/GetIndex",
}).done(function (data) {
$(data).each(function (index, element) {
viewModel.lookupCollection.push(element);
});
ko.applyBindings(viewMode);
}).error(function (ex) {
alert("Error");
});
});
Run Code Online (Sandbox Code Playgroud)
视图:
<table class="paginated">
<tr>
<th>
Name
</th>
<th>
Price
</th>
<th>
Category
</th>
<th></th>
</tr>
<tbody data-bind="foreach: lookupCollection">
<tr>
<td data-bind="text: Name"></td>
<td data-bind="text: price"></td>
<td data-bind="text: Category"></td>
<td>
<button class="btn btn-success">Edit</button>
<button class="btn btn-danger">Delete</button>
</td>
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
但是,我需要更多代码来分页列表项,我按照这个网站http://knockoutjs.com/examples/grid.html重播我的代码,但它没有显示我的列表项:
JS:
var initialData = …Run Code Online (Sandbox Code Playgroud) 我有这样的代码:
$scope.role.object_access_right = {contact:1,group:1,image:1,text:1,email_template:1,email:1,channel:1,campaign:1,invoice:1,user:1,account:1,tenant:1,}
Run Code Online (Sandbox Code Playgroud)
我这里有空数组,
$scope.access = [];
Run Code Online (Sandbox Code Playgroud)
如何将键推到空数组才能得到结果?
$scope.access = [contact,group,text ...]
Run Code Online (Sandbox Code Playgroud)